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

  • SEARCH
  • Home
  • 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 7561851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:15:57+00:00 2026-05-30T13:15:57+00:00

I have an Object base class, and I have several derived classes called Item,

  • 0

I have an Object base class, and I have several derived classes called Item, Person, and Location.

Because each of these are derived from Object I need to include Object.h in each of their header files, and I include all of the derived classes in my main.

Because I am doing that I am getting a redefinition error.

What I want to know is what is the correct way to include these files to avoid this error?

Thanks!

EDIT:

object.h

using namespace std;

class Object{
    string name;
    string description;

    public:
        Object();
        Object(string name, string description);
        void set_name(string name);
        void set_description(string description);
        string get_name();
        string get_description();
        ~Object();
};

item.h

using namespace std;

#include "object.h"

class Item : public Object{
    public:
        Item();
        Item(string name, string description);

};

locale.h

using namespace std;

#include "object.h"

class Locale : public Object{
    public:
        Locale();
        Locale(string name, string description);
};

main.cpp

#include <iostream>
#include <string>

#include "locale.h"
#include "item.h"


using namespace std;

int main(){
    return 0;
}
  • 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-30T13:15:58+00:00Added an answer on May 30, 2026 at 1:15 pm

    Strange, everybody I’ve met that hits this problem does not have a slightest idea what is going on and you have properly analysed the problem.

    Read this:
    http://en.wikipedia.org/wiki/Include_guard

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

Sidebar

Related Questions

I have a Base Class, called primitive Graphics. derived from this class are several
Let's say I have a Base class and several Derived classes. Is there any
I have a base class and several concrete classes that derive from it. Lets
I have a base class with several derived classes that extend it. I want
I have an ABC with several derived classes. To create these derived classes I
I have three classes: Base, Derived (inherits from Base), and Stats (which uses a
Newbie Python question. I have a class that inherits from several classes, and some
I have a base class object array into which I have typecasted many different
I have been writing several class templates that contain nested iterator classes, for which
I need some pretty approach to load polymorhic object I have base class 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.