Hey guys, I am having a really stupid template problem and I dont know why its happening. I am trying to create a linked list class as part of an assignment am using separate compilation as I always do to keep things tidy but it seems to be causing me some strange problems.
Here is a simplified WORKING version of my class. Its only just for illustration really as there is nothing interesting in there yet:
Link definition:
Main() function
And now using separate compilation:
Link header:
Link definion:
Main()
The error:
interestingly, i also made a function that returns a pointer to a container struct (i.e. container *) and this causes an error unless i put define the struct container first. I.e. put the private stuff before the public stuff in the class definition..
any thoughts on this?
Here is a simplified WORKING version of my class. Its only just for illustration really as there is nothing interesting in there yet:
Link definition:
Rich (BB code):
template<typename T>
class Link
{
public:
Link()
{
start_ptr = 0;
}
protected:
struct container
{
T* holder;
container* next_ptr;
};
container * start_ptr;
};
Rich (BB code):
#include "Link.h"
int main()
{
Link<int> test;
return 0;
}
Link header:
Rich (BB code):
class Link
{
public:
Link();
protected:
struct container
{
T* holder;
container* next_ptr;
};
container * start_ptr;
};
Rich (BB code):
#include "Link.h"
template<typename T>
Link<T>::Link()
{
start_ptr = 0;
}
Rich (BB code):
#include "Link.h"
int main()
{
Link<int> test;
return 0;
}
Rich (BB code):
1>------ Build started: Project: test link, Configuration: Debug Win32 ------
1>Compiling...
1>Link definition.cpp
1>Linking...
1>test link.obj : error LNK2019: unresolved external symbol "public: __thiscall Link<int>::Link<int>(void)" (??0?$Link@H@@QAE@XZ) referenced in function _main
1>Z:\College\Year 3\Programming\test link\Debug\test link.exe : fatal error LNK1120: 1 unresolved externals
1>Build log was saved at "file://z:\College\Year 3\Programming\test link\test link\Debug\BuildLog.htm"
1>test link - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
interestingly, i also made a function that returns a pointer to a container struct (i.e. container *) and this causes an error unless i put define the struct container first. I.e. put the private stuff before the public stuff in the class definition..
any thoughts on this?
Last edited: