using femath::Matrix;
>
> Consider this:
>
> ##########################
> namespace femath {
> ...
> template<class T> class Matrix
> {
> public:
> Matrix();
> Matrix(int rows);
> Matrix(int rows, int columns);
> virtual ~Matrix();
> ...
> };
> } //end namespace
>
> namespace fesolv {
>
> using femath::Matrix;
>
> class AbstractSolver
> {
> public:
> AbstractSolver(Model* model);
> virtual ~AbstractSolver();
>
> public:
> virtual void Solve()=0;
> ...
> protected:
> Model* _model;
> Matrix<double>* _systemstiffnessmatrix;
> ...
> };
>
> } //end namespace
>
> ##########################
>
> Everything compiles great but the linker tells me:
> AbstractSolver.obj : error LNK2019: unresolved external symbol "public:
> __thiscall femath::Matrix<double>::Matrix<double>(int)"
The constructor
template<typename T> Matrix<T>::Matrix(int);
is not implemented ...
> (??0?$Matrix@N@femath@@QAE@H@Z) referenced in function "public:
> __thiscall fesolv::AbstractSolver::AbstractSolver(class fesolv::Model
> *)" (??0AbstractSolver@fesolv@@QAE@PAVModel@1@@Z)
... and it is called from the constructor of fesolv::AbstractSolver.
Regards, Stephan
But where?
> Is there a "template<T>" phrase missing?
> What can be the problem?
>
TB
Compiler limitations. The template declarations and definitions must
be in the same translation unit.
Other solutions:
* Read about support for the 'export'-keyword for you compiler.
* #include the cpp-file after the declarations in the header-file.
TB
class Model;
namespace femath {
template<class T> class Matrix
{
public:
Matrix();
Matrix(int rows);
Matrix(int rows, int columns);
virtual ~Matrix();
};
} //end namespace
namespace fesolv {
using femath::Matrix;
class AbstractSolver
{
public:
AbstractSolver(Model* model);
virtual ~AbstractSolver();
public:
virtual void Solve()=0;
protected:
Model* model_;
Matrix<double>* systemstiffnessmatrix_;
};
}
int main(int argc, char* argv[])
{
}
Works for me.
Ben Pope
--
I'm not just a number. To many, I'm known as a string...
Test is a template, so the compiler must be able to see the definition.
http://www.parashift.com/c++-faq-lite/templates.html#faq-35.12