tenplate class error

S

Suneeel

Hi all,
I'm new at templates.
I've written this code and am compiling it with gcc 4.1.0 on RedHat
Linux 9.

/////////temptest.h//////////////
template <class T>
class tempclass
{
public:
tempclass();
void fun();
}


////////tempclass.cpp////////////////
#include "temptest.cpp"

template <class T>
temptest<T>::temptest()
{
}

template <class T>
void temptest<T>::fun()
{
}


I get the following errors

temptest.h:5: error: ISO C++ forbids declaration of 'tempclass'
with no type
temptest.cpp:4: error: expected constructor, destructor, or type
conversion before '<' token
temptest.cpp:10: error: expected initializer before '<' token

could someone please explain to me what the problem is...
 
A

Alf P. Steinbach

* (e-mail address removed):
/////////temptest.h//////////////
template <class T>
class tempclass
{
public:
tempclass();
void fun();
}

Missing semicolon.

////////tempclass.cpp////////////////
#include "temptest.cpp"

template <class T>
temptest<T>::temptest()
{
}

Not the same as the previously declared classname.

template <class T>
void temptest<T>::fun()
{
}

Not the same as the previously declared classname.


Note that to use this you have to either place the client code in
[tempclass.cpp] or #include that file, because the definitions must be
available to the compiler when compiling the client code.

The filename [tempclass.cpp] is then misleading; by common conventions
it indicates separate compilation, and there's no such thing for
templates unless you're using 'export' which current compilers simply do
not support (except Comeau, and a secret switch for the Intel compiler).

I suggest using the filename [tempclass.hpp].
 
F

Felix C. Stegerman

* (e-mail address removed) [2006-05-01 08:17]:
Hi all,
I'm new at templates.
I've written this code and am compiling it with gcc 4.1.0 on RedHat
Linux 9.

/////////temptest.h//////////////
template <class T>
class tempclass
{
public:
tempclass();
void fun();
}
I get the following errors

temptest.h:5: error: ISO C++ forbids declaration of 'tempclass'
with no type
temptest.cpp:4: error: expected constructor, destructor, or type
conversion before '<' token
temptest.cpp:10: error: expected initializer before '<' token

could someone please explain to me what the problem is...

Hi,

Try adding a `;' at the end of class declarations/definitions:
class X
{
/* ... */
}; <--


- Felix
 

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

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,197
Latest member
ScottChare

Latest Threads

Top