nbonneel
nbonneel

Reputation: 3326

templates and typedef

I have some class like :

 template<int DIMENSION, typename T> Vector { ... }  

Now, I want to specialize the typename and provide a new type using a typedef. I thus found an answer on StackOverflow at C++ typedef for partial templates

I thus did :

template < int DIMENSION> using VectorDouble= Vector<DIMENSION, double>;

This does not compile (error C2988: unrecognizable template declaration/definition). Is this because my compiler (Visual Studio 2008) doesn't allow it, or did I miss something ?

Thanks.

Upvotes: 0

Views: 1367

Answers (2)

Etienne de Martel
Etienne de Martel

Reputation: 36851

The answer you refer to says:

If you have a C++0x/C++1x compiler

C++1x is not yet current, so most compilers don't support its features. In particular, VC++9.0 (VS2008) has almost no support for them. VC++10 (VS2010) does support some features, but I don't know if what you need is one of those.

Upvotes: 2

Puppy
Puppy

Reputation: 146930

Template typedefs are supported in the next Standard- that is, basically, only the really, really, really new compilers support it. Even the newest VS doesn't support it becaue, well, it's not new enough, that's how new C++0x is.

In C++03, then typically, you use a struct.

template<int dimension> struct vector_double {
    typedef Vector<dimension, double> type;
};

Now it can be accessed like

int main() {
    vector_double<5>::type vec_double;
}

Upvotes: 3

Related Questions