If I do this :
my class works okCode:queue<Ccar *>q; cout << q.empty();
If I do
I get undefined reference to Ccar::q - what am I doing wrong ?Code:static queue<Ccar *>q; cout << q.empty();
If I do this :
my class works okCode:queue<Ccar *>q; cout << q.empty();
If I do
I get undefined reference to Ccar::q - what am I doing wrong ?Code:static queue<Ccar *>q; cout << q.empty();
Why do you want to make your queue static in the first place?
Mr. C: Author and Instructor
If I use a queue<Ccar *>q; then each object of the Ccar class will have it's own queue. I'd like to have a shared queue that all object of Ccar can access.
You can make data members and member functions static- but I have not seen making classes static. (Can' t do this is in Java either.)
Mr. C: Author and Instructor
I don't think that's what he meant.Originally posted by Mister C
You can make data members and member functions static- but I have not seen making classes static. (Can' t do this is in Java either.)
This works:
Code:class Ccar { public: //shared queue static std::queue<Ccar*> q; }; //place this definition in a .cpp file, not a header std::queue<Ccar*> Ccar::q; main() { //local static variable static std::queue<Ccar*> p; cout << Ccar::q.empty() << p.empty(); }
Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling
I got it and understand- I hope laasunde does! Sometimes knowing what a person wants done helps. I would do it the way you have done.
Mr. C: Author and Instructor
Thanks Sang-drax