By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,247 Members | 1,250 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,247 IT Pros & Developers. It's quick & easy.

Compilation error in VS.NET's C++ compiler

P: n/a
class A {
public:
template<class T> void f();
};

template<class T>
void A::f<T>() { }

When this code is compiled, the following error is produced:
error C2768: 'A::f' : illegal use of explicit template arguments

I changed the code to this:
template<class T>
void A::f() { }

This isn't producing compilation error. Any idea on why is this,
and what does this error means?

Oct 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
<pm*****@gmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com
class A {
public:
template<class T> void f();
};

template<class T>
void A::f<T>() { }

When this code is compiled, the following error is produced:
error C2768: 'A::f' : illegal use of explicit template arguments

I changed the code to this:
template<class T>
void A::f() { }

This isn't producing compilation error. Any idea on why is this,
Because the C++ language says so. You only use the template argument for f
if you want to specialise the member template, e.g.,

template<>
void A::f<int>() { }
and what does this error means?


It means you should do what you have done: drop the T.
--
John Carson

Oct 19 '05 #2

P: n/a
In article <11**********************@g49g2000cwa.googlegroups .com>,
<pm*****@gmail.com> wrote:
class A {
public:
template<class T> void f();
};

template<class T>
void A::f<T>() { }

When this code is compiled, the following error is produced:
error C2768: 'A::f' : illegal use of explicit template arguments

I changed the code to this:
template<class T>
void A::f() { }

This isn't producing compilation error. Any idea on why is this,
and what does this error means?


It means that for a "primary template" definition you don't
put the <T>
--
Greg Comeau / Celebrating 20 years of Comeauity!
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
Oct 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.