I would like to be able to use the classes Array and Matrix inside another class to perform calculations with arrays and matrices of type double and complex<double>. This second class, called LinAlgCalc, contains algorithms for solving A.x=b etc. I have attempted to define the class as follows
Expand|Select|Wrap|Line Numbers
- class LinAlgCalc
- {
- public:
- LinAlgCalc();
- //Member Functions
- //template <class T> void choldcmp(Matrix<T> &a,Matrix<T> &l,Array<T> &diag);
- template <class T> void func(Array<T> &x);
- private:
- // Constants used for the calculations can go here if necessary
- };
- LinAlgCalc::LinAlgCalc()
- {
- // Empty Constructor
- }
- template <class T> void LinAlgCalc::func(Array<T> &x)
- {
- x.print();
- }
Expand|Select|Wrap|Line Numbers
- int _tmain(int argc, _TCHAR* argv[])
- {
- Array<double> X(4);
- X[1]=-0.2; X[2]=-0.32; X[3]=13.52; X[4]=14.17;
- LinAlgCalc calcA; // declarate the object, no problem
- calcA.func(X); // try to use the object and not so good
- }
My class declaration is in a separate header file to the function definitions.
The error message I get when I try to build with the above code inside main is
------ Build started: Project: Linear_Algebra_Codes, Configuration: Debug Win32 ------
Compiling...
stdafx.cpp
Compiling...
LinAlgCodes.cpp
Linear_Algebra_Codes.cpp
Generating Code...
Linking...
Linear_Algebra_Codes.obj : error LNK2019: unresolved external symbol "public: void __thiscall LinAlgCalc::func<double>(class Array<double> &)" (??$func@N@LinAlgCalc@@QAEXAAV?$Array@N@@@Z) referenced in function _wmain
C:\Documents and Settings\Rob Sheehan\My Documents\See_Plus_Plus_Programming\Linear_Algebra _Codes\Debug\Linear_Algebra_Codes.exe : fatal error LNK1120: 1 unresolved externals
Build log was saved at "file://c:\Documents and Settings\Rob Sheehan\My Documents\See_Plus_Plus_Programming\Linear_Algebra _Codes\Linear_Algebra_Codes\Debug\BuildLog.htm"
Linear_Algebra_Codes - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========