0
我想纯虚函数。所以我写了相应的代码。 但我可能没有得到任何问题,因为这一点。我在代码中得到“cout没有命名类型”错误,即使我也包含了适当的头文件和命名空间。 请给出你的建议。“COUT”没有指定类型的错误
#include<iostream>
using namespace std;
struct S {
virtual void foo();
};
void S::foo() {
// body for the pure virtual function `S::foo`
cout<<"I am S::foo()" <<endl;
}
struct D : S {
cout <<"I am inside D::foo()" <<endl;
};
int main() {
S *ptr;
D d;
ptr=&d;
//ptr->foo();
d.S::foo(); // another static call to `S::foo`
cout <<"Inside main().." <<endl;
return 0;
}