470,849 Members | 1,074 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,849 developers. It's quick & easy.

tenplate class error

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...

May 1 '06 #1
2 1738
* Su*****@gmail.com:

/////////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].

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
May 1 '06 #2
* Su*****@gmail.com [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

--
Felix C. Stegerman <fl*@obfusk.net>

"Any sufficiently advanced bug is indistinguishable from a feature."
-- R. Kulawiec
May 1 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by rich | last post: by
5 posts views Thread by Nick Flandry | last post: by
reply views Thread by erik.erikson | last post: by
6 posts views Thread by sadegh | last post: by
8 posts views Thread by Jess | last post: by
1 post views Thread by BSand0764 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.