How do I use a generic array class inside another class?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • emaghero
    New Member
    • Oct 2006
    • 85

    #1

    How do I use a generic array class inside another class?

    I am trying to use the attached header file, which provides me with a generic way of declarating arrays and matrices of arbitrary size.

    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

    Code:
    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();
    }
    I am using MSVC 2008 and when I build the project I get no errors, however, when I attempt to perform an operation on a declarated LinAlgCalc object inside main, as such, I get a linking error that I do not know how to fix.

    Code:
    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
    }
    I cannot see why there is a problem. Am I using the template class incorrectly? Have I made a serious, or a stupid error? Any help would be greatly appreciated.

    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::fun c<double>(clas s Array<double> &)" (??$func@N@LinA lgCalc@@QAEXAAV ?$Array@N@@@Z) referenced in function _wmain
    C:\Documents and Settings\Rob Sheehan\My Documents\See_P lus_Plus_Progra mming\Linear_Al gebra_Codes\Deb ug\Linear_Algeb ra_Codes.exe : fatal error LNK1120: 1 unresolved externals
    Build log was saved at "file://c:\Documents and Settings\Rob Sheehan\My Documents\See_P lus_Plus_Progra mming\Linear_Al gebra_Codes\Lin ear_Algebra_Cod es\Debug\BuildL og.htm"
    Linear_Algebra_ Codes - 2 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
    Attached Files
Working...