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:
within the main program I instantiated 2 different objects of that class:
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
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