Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 554071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:40:17+00:00 2026-05-13T11:40:17+00:00

I am new to this website and I am trying a simple inheritance example

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T11:40:18+00:00Added an answer on May 13, 2026 at 11:40 am

    You need to include string:

    #include <string>
    

    That said, don’t use using namespace! Especially at file-scope, and definitely not in a header file. Now any unit that includes this file is forced to succumb to everything in the std namespace.

    Take that out, and qualify your names:

    bool filter(std::string word);
    

    It’s arguable more readable, too. Additionally, you should take your string as a const&:

    bool filter(const std::string& word);
    

    To avoid having to copy the string unnecessarily. Lastly, your header guards seem off. Should they be changed? As of now, they seem like the same ones that would be used in your other header, which might effectively stop it from being included.

    If you define READWORDS_H and then include ReadWords.h, and if that also has:

    #ifndef READWORDS_H
    #define READWORDS_H
    

    Then nothing in that file will be processed. If that’s the case, ReadWords as a class won’t be defined, and you cannot inherit from it. Your guard should probably be:

    READPUNCTWORDS_H
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Soooo, I am starting this new job soon where most of the code is
I am trying to create a simple questionnaire for a website but am fairly
Trying to make this simple applet - the first part just creates a simple
I'm trying to write a simple website (ASP.NET v4), which will call Windows Search,
I am trying to write a simple Google App Engine website that reads an
I am trying to login to this website https://www.virginmobile.com.au programatically (on the right there
I have found this example on StackOverflow: var people = new List<Person> { new
I'm new to this SCM, but since SVN is gaining popularity I was going
I am new to this. I want to design an image gallery in my
I keep reading about how great this new Canvas element for HTML5 is and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.