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 7818851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:43:19+00:00 2026-06-02T06:43:19+00:00

I am attempting to create a simple base class and another class that inherits

  • 0

I am attempting to create a simple base class and another class that inherits from it. I am getting the following error.

guard_room.h:17:1: error: expected class-name before ‘{’ token

I have looked at other posts and it seems like I have a circular dependency somewhere but I have done everything I have read to resolve it. Here are my classes

Base class room.h:

#ifndef _room
#define _room

template <typename U, typename T>
class room
{
    public:

        //default constructor
        room();

        //overloaded constructor
        room(U, T);


        //getters/setters
        void set_treasure(T);
        void set_name(U);
        T get_treasure() const;
        U get_name() const;

    private:

        U name;

        //room monster
        //monster room_monster

        T treasure;

};

#include "room.tem"

#endif

Inherited class guard_room.h:

#ifndef _guard_room
#define _guard_room

template <typename U, typename T> class room;

template <typename U, typename T>
class guard_room : public room
{
    public:

        //default constructor
        guard_room();

        //overloaded constructor
        guard_room(U, T, T) : room(U, T);

        //battle function?
        void battle();

    private:
        T dummy;

};

#include "guard_room.tem"
#endif

I am also thoroughly confused in where I need to put the includes for the base room class in my inherited class. Thanks for your help with this.

  • 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-06-02T06:43:20+00:00Added an answer on June 2, 2026 at 6:43 am

    Firstly, your derived class needs to be able to see the entire definition of your base class – you’ll need to include the header at the top of the derived class’ file. (a base class extends a derived class, so the base class is very much a part of the derived class)

    Also, room is a template and not a class – you can only inherit from a concrete class, so you need to specify the template parameters. i.e.

    #include "room.h"
    
    template <typename U, typename T>
    class guard_room : public room<U, T>
    

    Lastly – do your .tem files also contain header guards? (If not, you’ll need those in there too to avoid other compiler errors)


    Also, be aware that an initialiser list is part of a constructor’s definition, so the following is invalid

        guard_room(U, T, T) : room(U, T);
    

    If your constructor definition is elsewhere, then all you want here is

        guard_room(U, T, T);
    

    otherwise, it might just be enough to write

        guard_room(U u, T t1, T t2) : room(u, t1) {}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to create my 1st Simple DLL. I have a class(that's a
I am attempting to create a simple program that will keep a text log
I am attempting to create a simple application using Eclipse GEF that displays a
I'm attempting to create a simple backbone view that attaches to an <li> element.
I am attempting to create a hyperlink from an existing url that I would
I am attempting to create an abstracted getId method on my base Entity class
I'm attempting to create a simple example that would just alert the first 5
I am attempting to create a simple app that can send a text message
I am using C++ to create a simple DLL that I can use from
I am attempting to create a simple abacus for a beginner's programming course, 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.