templates
Tarjei Knapstad
tarjeik at chemcon.no
Fri Nov 30 12:37:30 GMT 2001
On Wed, 28 Nov 2001, Israel Fernandez Cabrera wrote:
> Hi every body:
>
> I'm having a problem when I tried to use templates in KDevelop, I've defined:
>
> template <class T> myclass{ /* ... */ }
>
> then I use:
>
> myclass <char*> newclass;
> newclass.insert("a word");
>
> *where insert is a valid function in myclass
> then the compiler give me the message bellow:
>
> undefined reference to myclass<char*>::insert(char*)
>
> Should I turn on "template" support just as "exception handling" support. By
> the way I couldn't turn on exceptio handling support.
> Please help me and explain me just as you explain a child.
No, this has nothing to do with KDevelop.
Your template class has not been instantiated for the char* type. Try
something like this to explicitly instantiate for char*
myclass.h:
template<class T1> myclass
{
void insert(T1);
};
myclass.cpp:
template class myclass<char*>;
template<class T1>
void
myclass<T1>::insert(T1)
{
/* insertion code here */
}
If you want to avoid explicitly instantiating your code, then the
implementation must be moved to the header file so that the compiler can
figure out for itself which code to generate. (Also have a look in the
info pages about template instantiation as someone else allready
suggested...)
Cheers,
--
Tarjei Knapstad, MSc
-
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