Singleton + nonstatic member - How to -


class scheduler:public kolejka { private: unsigned long real_time; scheduler(void) :real_time(0l){} scheduler(const scheduler &); scheduler& operator=(const scheduler&); ~scheduler() {}  public: std::deque <kolejka*> kolejka; //...                            rest of methods, not important here static scheduler& getinstance() {     unsigned long tmptime = 1;     (int = 0; < 10; i++)     {         kolejka* tmp = new kolejka(tmptime + 1);         kolejka.push_back(tmp); //error c2228: left of '.push_back' must                                 //have class/struct/union                     //intellisense: nonstatic member reference must relative                     //to specific object         tmptime++;                   delete tmp;     }     static scheduler instance;     return instance; } }; 

the problem written in code, understand should other way, how? i'm asking little :) don't know how rid of problem, tried without pointers, problem same.

edit: solved way:

    void setscheduler()     {         unsigned long tmptime = 1;         (int = 0; < 10; i++)         {             kolejka * tmp = new kolejka(tmptime + 1);             kolejka.push_back(tmp);             tmptime++;         }     }     static scheduler& getinstance()     {         static scheduler instance;         return instance;     }     }; 

and make empty deque, filling little bit later by

    scheduler::getinstance().setscheduler(); 

you can't access "non static" members of class static method. static method not know "object" thinking working with.

in order implement make local variable of type scheduler inside getinstance() function , edit variable. return it.

also in singleton have return existing instance if there was created earlier , not create new 1 every time.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -