There are PHP feature as new self
. Does exists the same in C++?
class A{
public function foo(){
return new self();
}
}
class B extends A{
}
$bar = new B();
bar->foo(); //will return B instance
I want to do the same in C++; Is it possible?
class A{
A* foo(){
return new _SELF_(SOME-CONSTRUCTOR-ARGS);
}
};
class B: public A{
};
B bar;
bar.foo(); //here expect B instance