Jump to content
  • Advertisement
Sign in to follow this  

Some templates, Some Typedefs

This topic is 4722 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've distilled my problem into a concise A,B,C problem. The problem is, is it valid C++?
template<class T>
struct A{
  T t;
};

struct B{
  typedef A<int >  B1;
};

template<class T>
struct C{
  typedef T::B1 C1;
};

I accidently tested this out in my Borland compiler and it worked fine. Then I tested it out in mingw3.4.2 and it did not work fine. Aparently it thinks that B1 has no type and fails. My biggest question is, is this valid c++? If anyone wants to put it in more concrete terms, A is an Octree type, B is a Conversion Policy and C is a Conversion structure that builds the destination Octree. I'm mostly confused as to why Borland eats it up and Mingw chokes on it. It doesn't seem like very ambiguous code.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by DigitalDelusion
typedef T::B1 C1;

should be
typedef typename T::B1 C1;


To expand on this, the reason typename is required here is that wheither or not B1 is a typename or member depends on what T is, making B1 what's known as a "dependant type" (IIRC). Ergo, you have:

struct foo {
static int bar;
typedef int baz;
};

template < typename T > void example() {
//Dependant stuff:
int i = T::bar;
//......^^^^^^^^ no typename keyword, we expect T's bar to not be a typename.
typedef typename T::baz i_type;
//......^^^^^^^^ typename keyword, we ONLY EXPECT T's baz member to be a typename.

//Nondependant stuff:
int j = foo::bar;
//......^^^^^^^^ no typename keyword, we KNOW foo's bar to not be a typename.
typedef foo::baz j_type;
//......^^^^^^^^ no typename keyword, we KNOW foo's baz to be a typename.
}

example< foo >();


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!