coucou8949
coucou8949

Reputation: 41

template parameters default value

I'm trying my very first template. the following code compiles :

template<class T,class C=int> class MyClass
{};

But not this :

#include <vector>

using namespace std;
template<class T,class C=vector<T>> class MyClass
{};

Yet i see the standard vector class template declared like this :

template < class T, class Alloc=allocator<T> > class vector
{};

The errors the compiler throws are :

*error: spurious '>>', use '>' to terminate a template argument list
*error: definition of 'class MyClass' inside template parameter list
*error: two or more data types in declaration of 'type name'
*error: expected '>' before ';' token
*error: expected unqualified-id before ';' token

Upvotes: 0

Views: 272

Answers (2)

coucou8949
coucou8949

Reputation: 41

the code was :

#include <vector>

using namespace std;
template<class T,class C=vector<T>> class MyClass
{};

but i should have written :

#include <vector>

template<class T,class C=std::vector<T> > class MyClass//with space between right angle brackets  : '> >'
{};

Upvotes: 1

CinchBlue
CinchBlue

Reputation: 6200

http://coliru.stacked-crooked.com/a/f93734d989e10446

No, it works. You just forgot the std namespace.

Upvotes: 2

Related Questions