I, unfortunately, can't describe my problem properly, but:
When I am trying to change a pointer value bar
defined in base class 'A' from a child class 'B' with method foo()
it gives me a segfault, because the pointer bar is null:
#include <iostream>
class A {
protected:
virtual void foo() {};
int* bar;
public:
void eval(){
foo();
std::cout << *bar;
}
};
class B : public A {
void foo() override {
*bar = 10; //segfault
}
};
int main(){
B* foobar = new B();
foobar->eval();
}
But, if the bar is not a pointer, but a normal variable it works fine.