Programm.cpp [url]http://pastebin.com/uaUa1jxL[/url]
Array.h [url]http://pastebin.com/XRr2zqEP[/url]
Array.cpp [url]http://pastebin.com/LqtuNajx[/url]
Whenever a class member that is implemented in cpp is invoked, I get the unresolved externals error.
Moving the implementation to header gets rid of the error, but then header will be a mess.
Must of missed something minor
First I didn't think that this was possible, but when I searched for a possible solution and found this:
[url]http://stackoverflow.com/questions/115703/storing-c-template-function-definitions-in-a-cpp-file[/url]
So it seems that you might be missing
[CPP]
template <class T>
[/CPP]
before each function declaration in your array.h .
Then in your array.cpp file add definitions for the types you want to use the templates with
for example like this:
[CPP]
using namespace std;
template void Array::Add<string>(string* str);
template bool Array::Delete<string>(string* str);
template int Array::Delete<string>(string*, bool delete);
template string* Array::Each<string>();
[/CPP]
Or if you don't know what types you are going to use, atleast I think that, you need to define the function bodies in your header.
Also as the solution in the link above suggested you should read
"-- 35.12, 35.13, and 35.14 from the C++ FAQ Lite:
[URL]http://www.parashift.com/c++-faq-lite/templates.html[/URL]"
However, please note that I'm not the worlds most experienced C++ programmer so I might have made a mistake somewhere, but I'm glad if I could be of any help.
[QUOTE=Boost;39462220]First I didn't think that this was possible, but when I searched for a possible solution and found this:
[url]http://stackoverflow.com/questions/115703/storing-c-template-function-definitions-in-a-cpp-file[/url]
So it seems that you might be missing
[CODE]
template <class T>
[/CODE]
before each function declaration in your array.h .
Then in your array.cpp file add definitions for the types you want to use the templates with
for example like this:
[CODE]
using namespace std;
template void Array::Add<string>(string* str);
template bool Array::Delete<string>(string* str);
template int Array::Delete<string>(string*, bool delete);
template string* Array::Each<string>();
[/CODE]
Or if you don't know what types you are going to use, atleast I think that, you need to define the function bodies in your header.
Also as the solution in the link above suggested you should read
"-- 35.12, 35.13, and 35.14 from the C++ FAQ Lite:
[URL]http://www.parashift.com/c++-faq-lite/templates.html[/URL]"
However, please note that I'm not the worlds most experienced C++ programmer so I might have made a mistake somewhere, but I'm glad if I could be of any help.[/QUOTE]
Thank you. Helped to clear few things out of the way.
So if I move implementation into a header should I expect any issues other than longer compile times?
[QUOTE=P1X3;39462456]Thank you. Helped to clear few things out of the way.
So if I move implementation into a header should I expect any issues other than longer compile times?[/QUOTE]
Well, this is what I had to do in my own project.
I haven't noticed an increase in the compile times because of this. So I think it won't cause any issues
and this is the recommended way (I think) if you don't know what classes are needed to have the templates.
Sorry, you need to Log In to post a reply to this thread.