C++ - templates problem..

Started by
7 comments, last by Aardvajk 17 years, 8 months ago
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?
True knowledge exists in knowing that you know nothing.
Advertisement
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.
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.
True knowledge exists in knowing that you know nothing.
Add #include "file.cpp" at the end of file.h. Don't include file.h in file.cpp.
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
True knowledge exists in knowing that you know nothing.
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.
how can i check when i reach the EOF
on this code:
while ( /*?*/ )
{
fin.read((char*)&myData,sizeof T);
}
what is the condition ?
True knowledge exists in knowing that you know nothing.
while(!fin.eof())
{
}

assuming fin is one of the C++ standard library fstreams.

This topic is closed to new replies.

Advertisement