c++ - Call non-static method from base class in static create method -


I want to write a static method, where I call the non-static method from base class.

& lt; BaseClass.h & gt;

  class base class {public: zero method (); }  

& lt; MyClass.h & gt;

  class MyClass: public base class {static MyClass * createMyClass (); }  

& lt; MyClass.cpp & gt;

  ... MyClass * MyClass :: createMyClass () {MyClass * myclass = new MyClass (); way(); // Invalid call invalid for myclass for return of non-static member function; } ...  

So do I have to call my base class method outside of my built-in class method, or is there any potential way of calling it?

Non-static methods need to be applied to an instance, and the compiler is sufficient to understand it Not to mention what example you want to apply (unless you are in an example method). You need to explicitly call the method on the example of MyClass : You just created:

  myclass-> method ();  

(Another way to think about this: In a non-static context, the syntax is using a method using the method (); & Gt; method (); Since you do not have "this" because you are in a fixed context, you need to supply "this" yourself.)


Comments