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;
}