c++ - "cout" does not name a type error -


i trying pure virtual function. have written code accordingly. ma not getting problem because of that. getting "cout not name type" error in code, have included proper header file , namespace well. please give suggestions this.

#include<iostream> using namespace std;  struct s {   virtual void foo(); };  void s::foo() {   // body pure virtual function `s::foo`  cout<<"i s::foo()" <<endl; }  struct d : s {   cout <<"i inside d::foo()" <<endl; };  int main() {   s *ptr;   d d;   ptr=&d;   //ptr->foo();   d.s::foo(); // static call `s::foo`   cout <<"inside main().." <<endl;   return 0; } 

you tried define struct direct code, looks wanted method around code:

struct d : s {   cout <<"i inside d::foo()" <<endl; }; 

should be

struct d : s {   virtual void foo() {     cout <<"i inside d::foo()" <<endl;   } }; 

Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -