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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:44:07+00:00 2026-06-16T16:44:07+00:00

I’m having an issue writing a class as part of a C++ program –

  • 0

I’m having an issue writing a class as part of a C++ program – in it I have three classes, FirstClass, SecondClass, and ThirdClass – First and Second classes both include ThirdClass.h, and in SecondClass I can declare them normally, however, in FirstClass the first declaration works fine, but any further declarations give me an error that “ThirdClass is not a type name”

here’s a snippet from the class that’s erroring

#include "ThirdClass.h"

class FirstClass
{
public:

    FirstClass(void);

    // This decleration of ThirdClass works fine
    FirstClass(ThirdClass ());
    FirstClass(const FirstClass& rhs);
    ~FirstClass(void);

private:

    //These are the two that're erroring
    ThirdClass nestedClass();

    void Init (ThirdClass ());
    void Copy (FirstClass);
};

I’m assuming that it’s something to do with both of them linking to the same header file, but i’ve been looking far and wide trying to find a solution online to no avail.
I did manage to get it working by placing the include inside a namespace, but I also read that this was very bad practice so I don’t really want to do it that way.

  • 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-16T16:44:08+00:00Added an answer on June 16, 2026 at 4:44 pm
    FirstClass(ThirdClass ());
    

    What is this supposed to do?

    If the type ThirdClass has been declared then it declares a constructor that takes the address of a function as its argument, that’s not what you wanted, right? ThirdClass () is the type of a function that takes no arguments and returns a ThirdClass, so your constructor argument is (the address of) a function of that type.

    If ThirdClass hasn’t been declared (and the error you’re getting implies it hasn’t been) then it is equivalent to:

    FirstClass ThirdClass();
    

    i.e. a (non-constructor) function called ThirdClass which returns a FirstClass object.

    You probably wanted it to be a constructor taking a ThirdClass object as the argument, which would be:

    FirstClass(ThirdClass);
    

    Or to avoid copying the argument (which is usually what you want):

    FirstClass(const ThirdClass&);
    

    Similarly for your Init function.

    The errors saying ThirdClass is not a type name indicate the type hasn’t been declared. We can only guess because you didn’t show a complete, self-contained example (no cookie for you) but you probably have #include "FirstClass.h" in your ThirdClass.h header, which causes circular reference and only one of the files is processed correctly.

    See these questions (and their answers) for more:
    cyclic dependency between header files
    C++ cyclical header dependency
    C++ error: 'Line2' has not been declared

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
We're building an app, our first using Rails 3, and we're having to build
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I have a small JavaScript validation script that validates inputs based on Regex. I
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a

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.