class C {
public:
C(int x):
_x(x){}
void print(){
std::cout<<_x<<std::endl;
}
int _x;
};
int main(){
C* c;
c->print(); // print 0 !
return 0;
}
c is a pointer of type C, but it is pointed to nothing ! so why c->print()
works ?
for example if I try
int* p;
I can't compile because am trying to point to nothing and compiler stops me.
I should use
int* p = nullptr;
or point to a given reference. should it be the same with a defined type C ? instead of 'int' I use 'C' so why different results?