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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:51:40+00:00 2026-06-12T09:51:40+00:00

I have code that declares a subclass template as private and then a member

  • 0

I have code that declares a subclass template as private and then a member as protected:

class X {
private:
    template <class T>
    class Y {
    public:
        void somethingToDo();
        // definition
    };
protected:
    Y<SomeType> _protectedMember;
    // More definition
};

class Z : public virtual X{
public:
    void f();
}
void Z::f() {
    ...
    _protectedMember.somethingToDo();
}

Originally I compiled this with gcc 4.3.4 and it accepted it. I then sent it off to try and build against GCC, IBM and Microsoft compilers on various platforms and the non-gcc compilers rejected it. Now that seems to be an indictment of (this version of) gcc’s standards compliance. But before I come to any conclusions, I’d like to verify what is technically correct.

Thanks.

  • 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-12T09:51:42+00:00Added an answer on June 12, 2026 at 9:51 am

    Your program appears valid to me (well, except for Y::somethingToDo being nonsensically private). Z::f() isn’t asking for access to any private names, only protected ones.

    If Z::f() tried to reference Y<T>, then the compiler should err. But Z::f() is only accessing _protectedMember, which is surely allowed.

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

Sidebar

Related Questions

I have code that looks like this: template<class T> class list { public: class
So I have a chunk of code that declares some classes, creates data, uses
I have an existing class that declares a virtual method and defines a default
I have a subclass of a class named Entity, and I wan't that subclass
I have a base class that declares and defines a constructor, but for some
I have java code that prepares a message for a MD5 munge private static
I have code something like the following, which declares a class and its name
I have a class that exposes an auto implemented property Enabled Public MustInherit Class
I have a class, lets call it A, and within that class definition I
We have a C# Web Service that declares itself using attributes. The code-behind file

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.