Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
edited title
Link
Sergey K.
  • 25.5k
  • 14
  • 112
  • 176

compile Compile error when I use C++ inheritance

made title more informative
Link
Alex Brown
  • 43.1k
  • 10
  • 96
  • 109

compile error when I use C++ inheritance problem

Source Link
Alex
  • 3
  • 1

C++ inheritance problem

I am new to this website and I am trying a simple inheritance example in C++. I checked my code lots of times and I really see nothing wrong with it, however the compilers gives me errors:

my code:

#ifndef READWORDS_H #define READWORDS_H using namespace std; #include "ReadWords.h" /** * ReadPunctWords inherits ReadWords, so MUST define the function filter. * It chooses to override the default constructor. */ class ReadPunctWords: public ReadWords { public: bool filter(string word); }; #endif 

And the messages I get from the compiler:

ReadPunctWords.h:11: error: expected class-name before '{' token ReadPunctWords.h:13: error: `string' has not been declared ReadPunctWords.h:13: error: ISO C++ forbids declaration of `word' with no type Tool completed with exit code 1 

I am really not sure where I get it wrong as it looks just fine to me? Thank you for any mistakes you might spot.