templated superclass fasten problem
i'm perplexing emanate c++ class, templated superclass. thought being, i simply emanate lots identical subclasses array superclasses have identical characteristics.
i have strong mysterious formula follows:
template_test.h
:
template<class baseclass>
class templated : open baseclass
{
public:
templated(int a);
practical int foo();
};
class base
{
protected:
base(int a);
public:
practical int foo() = 0;
protected:
int b;
};
template_test.cpp
:
#include "template_test.h"
base::base(int a)
: b(a+1)
{
}
template<class baseclass>
templated<baseclass>::templated(int a)
: baseclass(a)
{
}
template<class baseclass>
int templated<baseclass>::foo()
{
relapse this->b;
}
main.cpp
:
#include "template_test.h"
int main()
{
templated<base> test(1);
relapse test.foo();
}
when i build code, i linker errors, observant black templated<base>::templated(int)
templated<base>::foo()
can't found.
a discerning google suggests adding following main.cpp
solve problem:
template<> templated<base>::templated(int a);
template<> int templated<base>::foo();
but does solve problem. adding lines main.cpp
does work either. (though, interestingly, adding both gives 'multiply tangible symbol' errors linker, contingency doing something...)
however, putting formula source record does solve problem. while ok noddy instance above, genuine concentration i'm looking during spin massive unequivocally quick i forced put whole lot cpp file.
does anyone know i'm doing even possible? (how) i solve linker errors?
i assume i methods class templated
inline work, nonetheless doesn't seem ideal either.
Comments
Post a Comment