This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Error: L6218E Usin templates and classes

test.h:
-------

template <class T>
class test
{

public:

T * Pointer;

protected:

int * test_count;

public:

test(unsigned int n);

~test();
};

test.cpp:
---------

#include "test.h"

template<class T>
test<T>::test( unsigned int n)
{ My Code..
}

template<class T>
test<T>::~test()
{ My Code...
}

Main.cpp:
---------
#include "test.h"
int main(void){

test<char> Mydata1(10);

....
}

Built error:

testc++.axf: Error: L6218E: Undefined symbol test<char>::test(unsigned) (referred from main.o).
testc++.axf: Error: L6218E: Undefined symbol test<char>::~test() (referred from main.o).

Well, the strange thing is if I put the function in the same way out of the class, but in the file test.h everything works!!!.

What is the problem? That putting the functions in and other file the linker don't see them.

I am using the compiler commands --C99 --cpp and --force_new_nothrow.

Thanks

Parents
  • It is because Keil only accepts template classes in a single header file. Copy the contents of test.cpp into test.h.

    Since template classes are written internally for each new type, there is no object file for template class implementation. So, it is ok to write it in the header file.

Reply
  • It is because Keil only accepts template classes in a single header file. Copy the contents of test.cpp into test.h.

    Since template classes are written internally for each new type, there is no object file for template class implementation. So, it is ok to write it in the header file.

Children
No data