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
Post a Comment