C++ call virtual method in child class

c++, virtual-functions

Solution

Without an explicit initialization of the member inner, it's possible for it to be both not NULL and point to invalid memory. Can you show us the code that explicitly initalizes inner?

An appropriate constructor for A would be the following

protected:
A() : inner(NULL) {
  ...
}

Problem

i have the following classes: ``` class A { protected: A *inner; public: .... virtual void doSomething() = 0; .... } class B: public A { ... void doSomething() { if(inner != NULL) inner->doSomething(); } ... } ``` When I use `inner->doSomething()` I get a segmentation fault. What should I do in order to call `inner->doSomething()` in the B class? thanks in advance.

Original source