Creating a vector of queues

Joined
Jan 19, 2025
Messages
1
Reaction score
0
Hi everyone, Im working right now on an object which has a vector with queues in it. And the data which is stored within this queues is diverse. So I work with templates:
C++:
class Node {
    
    public:
    
    Node(T myType, int anz = 5) {

        this->elementCnt = 5;
        std::queue<T> q;
        q.push(myType);
        Base.push_back(q);
        //Base.push_back(std::queue<T> q.push(myType));
        
    }


    private:
    
    int         elementCnt;
    std::vector<std::queue<T>> Base;

};

within the main program I instantiated 2 different objects of that class:
Code:
int main(int argc, char *argv[])
{
    int n = 5;

    Node<const char*> v("hallo",n);
    Node<int> d(7,n);

    return 0;
}

Now this example is highly simplified to point out what Im talking about but it works. The datatype is getting excepted and the objects and methods are getting created for int and cstring. But I ask: could that can be made simpler. I commented out the line with my idea of don't create a temp std::queue and inserting it direct into the std::vector?
Base.push_back(std::queue<T> q.push(myType)); but this is not accepted by the compiler. Is it possible anyway, and if it is, how?

Thank you

BR Christian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,183
Messages
2,570,967
Members
47,518
Latest member
RomanGratt

Latest Threads

Top