problem declaring template

D

desktop

When I try to compile this template:

template <typename T>
class ElementT<std::vector<T> > {
public:
typedef T Type;
};

I get the error:

main.cpp:11: error: ‘ElementT’ is not a template
make: *** [main.o] Error 1


What is causing this error?
 
Z

Zeppe

desktop said:
When I try to compile this template:

template <typename T>
class ElementT<std::vector<T> > {
public:
typedef T Type;
};

I get the error:

main.cpp:11: error: ‘ElementT’ is not a template
make: *** [main.o] Error 1


What is causing this error?

What is std::vector<T>? What are you trying to do?
The correct template declaration is:

template <typename T>
class ElementT{
public:
typedef T Type;
};

Regards,

Zeppe
 
D

desktop

Zeppe said:
desktop said:
When I try to compile this template:

template <typename T>
class ElementT<std::vector<T> > {
public:
typedef T Type;
};

I get the error:

main.cpp:11: error: ‘ElementT’ is not a template
make: *** [main.o] Error 1


What is causing this error?

What is std::vector<T>? What are you trying to do?
The correct template declaration is:

template <typename T>
class ElementT{
public:
typedef T Type;
};

Regards,

Zeppe

It works if I first type:


template <typename T>
class ElementT;


and then the partial specialization:

template <typename T>
class ElementT<std::vector<T> > {
public:
typedef T Type;
};


It seems that when doing partial specialization you first need to define
the class as a template.
 
Z

Zeppe

desktop said:
It works if I first type:


template <typename T>
class ElementT;


and then the partial specialization:

template <typename T>
class ElementT<std::vector<T> > {
public:
typedef T Type;
};


It seems that when doing partial specialization you first need to define
the class as a template.

Oh, so you wanted to do a template specialization! If you think about
that, it's quite reasonable that you have to define something before
specializing it, isn't it?

Regards,

Zeppe
 
S

Sylvester Hesp

desktop said:
Zeppe said:
desktop said:
When I try to compile this template:

template <typename T>
class ElementT<std::vector<T> > {
public:
typedef T Type; };

I get the error:

main.cpp:11: error: ‘ElementT’ is not a template
make: *** [main.o] Error 1


What is causing this error?

What is std::vector<T>? What are you trying to do?
The correct template declaration is:

template <typename T>
class ElementT{
public:
typedef T Type;
};

Regards,

Zeppe

It works if I first type:


template <typename T>
class ElementT;


and then the partial specialization:

template <typename T>
class ElementT<std::vector<T> > {
public:
typedef T Type; };


It seems that when doing partial specialization you first need to define
the class as a template.

That is correct, although you have "definition" and "declaration" mixed up.
You are trying to *define* a partial specialization without first
*declaring* the general template, which is an error.

- Sylvester Hesp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,297
Messages
2,571,530
Members
48,251
Latest member
Amelia8778

Latest Threads

Top