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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:10:11+00:00 2026-05-13T19:10:11+00:00

I was happily working in C++, until compilation time arrived. I’ve got several classes

  • 0

I was happily working in C++, until compilation time arrived.

I’ve got several classes inside some namespace (let’s call it N); two of these classes correspond to one base class, and other derived from it. Each class has its own pair of .hpp and .cpp files; I think it’d look like:

namespace N{

    class Base{
    };

    class Derived: public Base{
    };

}

However, g++ (maybe linker) keeps telling me:

Derived.hpp:n: error: expected class-name before ‘{’ token

It doesn’t recognize Base as a class, even when I have correctly #include’ed the hpp file corresponding to its definition to Derived’s .hpp!

“It’s something with #includes”, I thought, since these classes’ .hpps are #included in other files, so I added this to Derived declaration in Derived.hpp:

#include "Base.hpp"
namespace N{

    class Base;

    class Derived: public Base{
    };
}

And now g++ complains:

Derived.hpp:n: error: invalid use of incomplete type ‘struct N::Base’

So, I got lost here. Please help me, I will apreciate it a lot. 🙂

(By the way, I’m rather experienced in Python, not C++, so this issues are really strange to me. Also, I changed classes’ names and stuff :).

Edit: A more exact representation of my files is:

File Pieza.hpp
-----------------------
#include "Celda.hpp"

namespace Reglas
{
    class Pieza
    {    
        public:
        Pieza() {}
        virtual ~Pieza() {}

        private: 
        Celda *c; 
    };
}


File Jugador.hpp
-----------------------
#include "Jugada.hpp" 
#include "Excepciones.hpp"
#include "Pieza.hpp"
namespace Reglas
{  
//compiler asked for these :S
class Celda;
class Tablero;
    class Jugador : public Pieza
    {
        public:
        Jugador() {}
        virtual ~Jugador() {}
    };
}
  • 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-13T19:10:11+00:00Added an answer on May 13, 2026 at 7:10 pm
    Derived.hpp:n: error: invalid use of incomplete type ‘struct N::Base’
    

    This makes me think that you didn’t #include "Base.hpp in the Derived.cpp source file.

    EDIT: In your Derived.cpp, try changing the order of #includes to:

    #include "base.hpp"
    #include "derived.hpp"
    
    // .. rest of your code ..
    

    Like this:

    // Derived.hpp
    #pragma once
    
    namespace foo
    {
        class Base;
    
        class Derived : public Base
        {
        public:
            Derived();
    
            ~Derived();
        };
    }
    

    // Derived.cpp
    #include "base.hpp"
    #include "derived.hpp"
    
    namespace foo
    {
        Derived::Derived()
        {
        }
    
        Derived::~Derived()
        {
        }
    }
    

    So, you’re going to want to edit Jugador.hpp to look like this:

    // Jugador.hpp
    #include "Pieza.hpp" // move this above Jugada.hpp
    #include "Jugada.hpp" 
    #include "Excepciones.hpp"
    namespace Reglas
    {  
    //compiler asked for these :S
    class Celda;
    class Tablero;
        class Jugador : public Pieza
        {
            public:
            Jugador() {}
            virtual ~Jugador() {}
        };
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 411k
  • Answers 411k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer $quote->{'P-E'}; May 15, 2026 at 7:40 am
  • Editorial Team
    Editorial Team added an answer I think it's important to separate the idea of historical… May 15, 2026 at 7:40 am
  • Editorial Team
    Editorial Team added an answer Looks like you can specify it in the JSON data… May 15, 2026 at 7:40 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.