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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:03:32+00:00 2026-05-26T23:03:32+00:00

I was playing with Visual Studio and templates. Consider this code struct Foo {

  • 0

I was playing with Visual Studio and templates.

Consider this code

struct Foo
{
  struct Bar
  {
  };

  static const int Bar=42;
};

template<typename T>
void MyFunction()
{
  typename T::Bar f;  
}

int main()
{
    MyFunction<Foo>();
    return 0;
}

When I compile this is either Visual Studio 2008 and 11, I get the following error

error C2146: syntax error : missing ';' before identifier 'f'

Is Visual Studio correct in this regard ? Is the code violating any standards ?

If I change the code to

struct Foo
{
  struct Bar
  {
  };

  static const int Bar=42;
};


void SecondFunction( const int& )
{
}

template<typename T>
void MyFunction()
{
  SecondFunction( T::Bar ); 
}

int main()
{
    MyFunction<Foo>();
    return 0;
}

it compiles without any warnings. In Foo::BLAH a member preferred over a type in case of conflicts ?

EDIT Tests on G++ 4.2.1

struct Foo
{
  static const int Bar=42;
};


void SecondFunction(const int& x)
{
}

template<typename T>
void MyFunction()
{
  int x = Foo::Bar;
}

int main()
{
  MyFunction<Foo>();
  return 0;
}

compiles OK.

struct Foo
{
  static const int Bar=42;
};


void SecondFunction(const int& x)
{
}

template<typename T>
void MyFunction()
{
  SecondFunction(T::Bar);
}

int main()
{
  MyFunction<Foo>();
  return 0;
}

Gives me these errors

Undefined symbols:
“Foo::Bar”, referenced from:
void MyFunction() in cck498aS.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

  • 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-26T23:03:32+00:00Added an answer on May 26, 2026 at 11:03 pm

    In C++, named entities fall into one of three distinct ontological tiers: values, types and templates.

    If a dependent name is of an unknown tier, then you must tell the compiler what it is:

    • If you say nothing, it’s a value.

    • If you say typename, it’s a type.

    • If you say template, it’s a template.

    So T::Bar, being a dependent name inside the MyFunction template, is automatically assumed to refer to a value, hence the int member Foo::Bar. On the other hand, in the first example, typename T::Bar indeed refers to the member type Foo::Bar.

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

Sidebar

Related Questions

I've just started playing with domain-specific tools development, and I'm playing with Visual Studio
I have been playing around with Visual Studio 2010 over the past few days
Whilst playing around with resources in my visual studio 10 project, I came across
I have been playing with the Command Window in Visual Studio (View->Other Windows->Command Window).
I just upgraded to Visual Studio 2010, and I am playing around with the
I am currently playing around with VB.Net using Visual Studio 2010 (.Net 4.0) and
I'm using Visual Studio 2010, and have the tangibleT4EditorPlusModellingTools installed. I'm just playing around
I'm playing about with an addin to Visual Studio 2005 that calls an external
I was just playing around with exceptions in the visual studio and with the
I was playing around with F# (Visual Studio 2010 beta 1), and I wrote

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.