Sign in to follow this  
lord4n

C++ - templates problem..

Recommended Posts

lord4n    100
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?

Share this post


Link to post
Share on other sites
Aardvajk    13207
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.

Share this post


Link to post
Share on other sites
ToohrVyk    1595
Template method definitions must be visible from the point of instantiation, AKA you cannot separate the implementation of a template from its definition.

Share this post


Link to post
Share on other sites
lord4n    100
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.

Share this post


Link to post
Share on other sites
lord4n    100
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

Share this post


Link to post
Share on other sites
Brother Bob    10344
Look at the error message.

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this