c++ - Object Instantiation in c ++ with a protected constructor -


i have c++ class , want initialize object of type:

class myclass  { public:     /**      *  creates instance of class.      *  @return pointer created object.      */     static myclass * create ();   protected:     // explicit protected constructor      //and copy-constructor, use create() create  instance of object.     myclass();  } 

to create instance, did this:

static myclass * m_object = myclass.create(); 

but got warnings , errors:

   warning c4832: token '.' illegal after udt 'myclass'     error c2275: 'myclass' : illegal use of type expression     error c2228: left of '.create' must have class/struct/union 

how instantiate object?

in c++, static variables/methods access using scope resolution (::) operator.

change code to

static myclass * m_object = myclass::create(); 

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -