473,385 Members | 1,582 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 1918
* 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Rob F | last post by:
I am trying to compile a string class which was working before but subsequent attempts to make it more 'object orientated' (privatizing the member variables and implenting query functions) it...
5
by: rich | last post by:
Hi there, I defined a class template (MyClass) and some member variables and functions, as following: template<class T1, class T2> class MyClass { ... struct m_variable
5
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS...
2
by: dasilva109 | last post by:
Hi guys I am new to C++ and need urgent help with this part of my code for a uni coursework I have to submit by Thursday //ClientData.h #ifndef CLIENTDATA_H #define CLIENTDATA_H #include...
0
by: erik.erikson | last post by:
I am getting a compiler error that I can't well explain or even understand the origin of (though I boiled it down close...). Below is a bare-bones example. What I am doing is defining the...
6
by: sadegh | last post by:
Hi I have a problem with my program in VC++6 When I compile it, the following errors are listed. I spend a lot of time on the groups.google.com to find its reason, but none of comments could...
8
by: Jess | last post by:
Hi, I have a template function that triggered some compiler error. The abridged version of the class and function is: #include<memory> using namespace std; template <class T>
1
by: BSand0764 | last post by:
I'm getting an error that I can't seem to resolve. When I compile the Functor related logic in a test program, the files compile and execute properly (see Listing #1). However, when I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.