typename resolution in cases of ambiguity

Posted by parapura rajkumar on Stack Overflow See other posts from Stack Overflow or by parapura rajkumar
Published on 2011-11-16T01:37:58Z Indexed on 2011/11/16 1:50 UTC
Read the original article Hit count: 255

Filed under:
|

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 ?

© Stack Overflow or respective owner

Related posts about c++

Related posts about visual-c++