C++ templates
Mark Johnson
mark.johnson at onfiber.com
Thu Nov 16 23:00:07 GMT 2000
I as far as I know, templates can't be split up into header and source
files... the template class and implementation must exist in one unit (i.e.
a header file). This is required by the compiler. I have never been able
to successfully split up a template class into two units.
-----Original Message-----
From: Benjamin Ellis [mailto:bmellis at uark.edu]
Sent: Thursday, November 16, 2000 4:14 PM
To: kdevelop at kdevelop.org
Subject: Re: C++ templates
> My Problem is that I'd like to implement a class-contructor, that takes
the
> generic types of my template as argument. When I'm defining the method
> within the class declaration, everything works fine, but after spliting
the
> class code apart, into .cpp and .hpp the compiler nervs me, that the > >
>constructor's arguments are not enough defined... Could anyone help me?
I'm not sure if this will answer your question or not... but say you have
this class declaration:
----------------------------------------
template <class T>
class MyClass
{
MyClass(T);
void SomeFunction();
};
-----------------------------------------
you would therefore, in a seperate file, declare the function definitions as
this:
------------------------------------------
template <class T>
MyClass<T>::MyClass(T genericDataType)
{
//........
}
and ...
template <class T>
void MyClass<T>::SomeFunction()
{
//........
}
--------------------------------------------
Remember, even if some of your class methods don't use the template type,
they still have to be defined as a template function.
hope that helps.. make sure you pay attention to how the class methods are
written in the .cpp file as shown above.
-Ben
-
to unsubscribe from this list send an email to kdevelop-request at kdevelop.org
with the following body:
unsubscribe »your-email-address«
-
to unsubscribe from this list send an email to kdevelop-request at kdevelop.org with the following body:
unsubscribe »your-email-address«
More information about the KDevelop
mailing list