C++ - templates problem..
heres the code:
http://rafb.net/paste/results/Uai5z982.html
and im getting this error:
http://rafb.net/paste/results/w3RBYG97.html
why, and how can i fix it?
Unfortunately you can't seperate template code into a .h and a .cpp like that. The compiler needs to be able to see the implementation of the functions in the code that uses it.
You need to put all the .cpp code into the bottom of the .h file, either directly or with an include. If you have a look at the STL include files, you'll see that they normally include another file right at the bottom with all the implementation in (Borland), or they have all the implementation in the same file (Microsoft).
No way round this I'm afraid. Template code cannot be compiled as a seperate unit like normal code.
You need to put all the .cpp code into the bottom of the .h file, either directly or with an include. If you have a look at the STL include files, you'll see that they normally include another file right at the bottom with all the implementation in (Borland), or they have all the implementation in the same file (Microsoft).
No way round this I'm afraid. Template code cannot be compiled as a seperate unit like normal code.
Template method definitions must be visible from the point of instantiation, AKA you cannot separate the implementation of a template from its definition.
alright its working now
but its not looking so good
when its all togeder
so how can i include the .cpp file into the .h one?
as EasilyConfused said.
but its not looking so good
when its all togeder
so how can i include the .cpp file into the .h one?
as EasilyConfused said.
still got some bugs in my code
the code:
http://rafb.net/paste/results/nUD2Yr32.html
the errors:
http://rafb.net/paste/results/39l0zv19.html
the code:
http://rafb.net/paste/results/nUD2Yr32.html
the errors:
http://rafb.net/paste/results/39l0zv19.html
Look at the error message.
The error message says you're passing an std::string, but it cannot be converted to a const char * that open takes. So you need to pass it a const char * instead. Call the c_str member function on the string object to get a const char * representation of the string.
c:\[...]\cdatamanager.h(52) : error C2664: [...] : cannot convert parameter 1 from 'std::string' to 'const char *'
The error message says you're passing an std::string, but it cannot be converted to a const char * that open takes. So you need to pass it a const char * instead. Call the c_str member function on the string object to get a const char * representation of the string.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement