K
Kefik
Hi, I'm new to C++ so may be this is a trivial problem but...
I'm trying to create a template class, in header file I declared it
and in source file implement, seems nice, but linker won't link
constructors and destructors as I'd like him to do.
To demonstrate problem, I'm trying to compile this...
------------------------
my.h:
template <class A> class my{
public:
my<A>();
~my<A>();
};
-------------------------
my.cpp:
#include "my.h"
template <class A> my<A>::my(){};
template <class A> my<A>::~my(){};
--------------------------
main.cpp:
#include "my.h"
int main(int argc, char* argv[])
{
my<int> b;
// linker error, Unresolved External Symbol "public:__thiscall
my<int>::my<int>(void)" .... referenced in function
_main
return 0;
};
--------------------
More strange thing to me appears (that's why I'm out of ideas) that
this works fine with non-template classes.
What's wrong?
THX in advance for any ideas.
I'm trying to create a template class, in header file I declared it
and in source file implement, seems nice, but linker won't link
constructors and destructors as I'd like him to do.
To demonstrate problem, I'm trying to compile this...
------------------------
my.h:
template <class A> class my{
public:
my<A>();
~my<A>();
};
-------------------------
my.cpp:
#include "my.h"
template <class A> my<A>::my(){};
template <class A> my<A>::~my(){};
--------------------------
main.cpp:
#include "my.h"
int main(int argc, char* argv[])
{
my<int> b;
// linker error, Unresolved External Symbol "public:__thiscall
my<int>::my<int>(void)" .... referenced in function
_main
return 0;
};
--------------------
More strange thing to me appears (that's why I'm out of ideas) that
this works fine with non-template classes.
What's wrong?
THX in advance for any ideas.