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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:52:13+00:00 2026-05-14T01:52:13+00:00

I am attempting to use the fully qualified name of my nested class as

  • 0

I am attempting to use the fully qualified name of my nested class as below, but the compiler is balking!

template <class T> class Apple {
    //constructors, members, whatevers, etc...
public:
    class Banana {
    public:
        Banana() {
            //etc...
        }
        //other constructors, members, etc...
    };
};

template <class K> class Carrot{
public:
    //etc...
    void problemFunction()
    {
        Apple<int>::Banana freshBanana = someVar.returnsABanana(); //line 85
        giveMonkey(freshBanana);  //line 86
    }
};

My issue is, the compiler says:

Carrot.h:85: error: expected ';' before 'freshBanana'
Carrot.h:86: error: 'freshBanana' was not declared in this scope

I had thought that using the fully qualified name permitted me to access this nested class? It’s probably going to smack me in the face, but what on earth am I not seeing here??

  • 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-14T01:52:14+00:00Added an answer on May 14, 2026 at 1:52 am

    That’s probably not what you do in your code. The error message looks like you do this

    Apple<K>::Banana freshBanana = someVar.returnsABanana();
    

    The compiler has to know before it parses the code whether a name names a type or not. In this case, when it parses, it cannot know because what type K is, is not yet known (you could have a specialization for Apple<int> that doesn’t have that nested class). So it assumes Apple<K>::Banana is not a type. But then, it is an expression and an operator is needed after it or a semicolon.

    You can fix it by inserting typename:

    typename Apple<K>::Banana freshBanana = someVar.returnsABanana();
    

    That asserts the name is a type, and the compiler then knows to parse this as a declaration.

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

Sidebar

Related Questions

I am attempting to use the data sources pluigin for rubymine 4.0.3 but I
I'm attempting to use Graticule to geocode an address but I'm running into an
below is what I'm attempting to use for my site, this php page shows
I have a base Class akin to the code below. I'm attempting to overload
I'm attempting to use the Microsoft crypto APIs to compute an MD5 hash, but
I'm attempting to use an XBAP to acquire TWAIN Images but I'm not even
2nd UPDATE Almost there!! But getting a ValueError: Attempting to use a port that
Attempting to use the data series from this example no longer passes the JSONLint
Attempting to use XStream's JavaBeanConverter and running into an issue. Most likely I'm missng
When attempting to use HttpWebRequest to retrieve a page from my dev server, I

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.