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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:09:14+00:00 2026-05-28T14:09:14+00:00

This one doesn’t want to compile: class MainClass { public: … private: class NestedClass

  • 0

This one doesn’t want to compile:

class MainClass
{
public:
    ...

private:
    class NestedClass
    { //Line 39
        ...
    };

    class NestedClass * getNestedClassFor(int i);
};

The compiler says:

error: ‘class MainClass::NestedClass’ is private

However, if I made NestedClass public, it would work.

Why doesn’t it work? It’s not as though I’m exporting a nested class through a public method? It’s just a private method returning a pointer to a private class. Any ideas?

Thanks!

Update

Fixed the semi-columns. They’re not the problem. Neither is writing class in front of NestedClass.

Here’s the error message:

MainClass.h: In function ‘MainClass::NestedClass* getNestedClassFor(int i)’:

MainClass.h:39: error: ‘class MainClass::NestedClass’ is private

MainClass.cpp:49: error: within this context

Here’s the part of the .cpp file that’s also complaining:

class MainClass::NestedClass * getNestedClassFor(int i) //Line 49
{
    return NULL;
}
  • 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-28T14:09:14+00:00Added an answer on May 28, 2026 at 2:09 pm

    Had forgotten to add the class scope in the .cpp, i.e.

    class MainClass::NestedClass * getNestedClassFor(int i)
    {
       //...
    }
    

    Should be

    class MainClass::NestedClass * MainClass::getNestedClassFor(int i)
    {
       //...
    }
    

    Stupid me!

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

Sidebar

Related Questions

$('body, html').replace(., ); I tried it, but this one doesn't work. I want to
How does one do this? If I want to analyze how something is getting
How does one do this in c#? Let's say that myclass has : private
Why the following code works: char *p; p=hello; printf(%s\n,p); While this one doesn't: char
I want to find a <td role=foo class=one two three four> within a <div
Here the thing, other PDO works well, but this one doesn't. I have tried
for some reason this one doesn't work anymore admin_club_path(club) but following does work admin_club_path(club.id)
What pattern do I have to use for such String cos this one doesn't
I need a good OLEDate java implementation, and this one does not seem to
How does one do this? The SYSCOLUMNS system table only has columns for tables.

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.