class a
{
virtual void foo(void) ;
};
class b : public a
{
public:
virtual void foo(void)
{
cout<< "class b";
}
};
int main ( )
{
class a *b_ptr = new b ;
b_ptr->foo();
}
Run Code Online (Sandbox Code Playgroud)
请指导我为什么b_ptr-> foo()不会调用类b的foo()函数?
在下面的例子中
class X
{
int *r;
public:
X() {
cout << "X is created";
r = new int[10];
};
~X() {
cout<< "X is destroyed";
delete [] r;
};
};
class Y
{
public:
Y() {
X x;
throw 44;
};
~Y() {
cout << "Y is destroyed";
};
};
Run Code Online (Sandbox Code Playgroud)
我从一个站点得到了RAII的这个例子并且有些疑惑.请帮忙.