473,385 Members | 2,028 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

emaghero
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

Expand|Select|Wrap|Line Numbers
  1. class LinAlgCalc
  2. {
  3. public:
  4.     LinAlgCalc();
  5.  
  6.     //Member Functions
  7.     //template <class T> void choldcmp(Matrix<T> &a,Matrix<T> &l,Array<T> &diag);
  8.  
  9.     template <class T> void func(Array<T> &x);
  10.  
  11. private:
  12.     // Constants used for the calculations can go here if necessary
  13.  
  14. };
  15.  
  16. LinAlgCalc::LinAlgCalc()
  17. {
  18.     // Empty Constructor
  19. }
  20.  
  21. template <class T> void LinAlgCalc::func(Array<T> &x)
  22. {
  23.     x.print();
  24. }
  25.  
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.

Expand|Select|Wrap|Line Numbers
  1. int _tmain(int argc, _TCHAR* argv[])
  2. {
  3. Array<double> X(4);
  4. X[1]=-0.2; X[2]=-0.32; X[3]=13.52; X[4]=14.17;
  5.  
  6. LinAlgCalc calcA; // declarate the object, no problem
  7.  
  8. calcA.func(X); // try to use the object and not so good
  9. }
  10.  
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::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 ==========
Attached Files
File Type: zip TheMatrix.zip (3.2 KB, 65 views)
Feb 11 '11 #1
0 1341

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Saurabh Kumar | last post by:
I have a byte array, which i need to send to a class, where it will be stored in an arraylist. I use the following property in the class to accept the byte array, but it seems that the array is...
3
by: Scott McNair | last post by:
Hi, I'm trying to populate a 2-dimensional array by assigning each item its own instance of a class, for example: Dim SubSector(8,10) As New SystemClass ....where SystemClass is a class...
14
by: Peter Hallett | last post by:
I would like to set up a string array as a class member, or field, and then populate this array by reading in from a text file, but I cannot find the appropriate syntax. The getter and setter are...
4
by: Miro | last post by:
Vb2003, im still learning vb.net but I do not understand my output from this logic. If someone can help me out here. Cor Ligthert, you I believe were on the right track of what Im trying to...
1
by: icksa1 | last post by:
Hi: I have a templated class, inside of which I declared another class, as shown below: template <class T, int nclass array { class subclass { };
9
by: mps | last post by:
I want to define a class that has a generic parameter that is itself a generic class. For example, if I have a generic IQueue<Tinterface, and class A wants to make use of a generic class that...
0
by: Kristopher Wragg | last post by:
Hi, I'm having a problem with XMLSerializer, I have classes like the following: public abstract class EulerObject { private Rectangle rect; private string guid = "";
1
by: scripty | last post by:
Hello, I am trying to implement hash table functionality using templates. I need to declare the hash table element as a struct or class inside the HTable template... I get...
2
by: yogeshbhandare | last post by:
Is there any special reason that we cannot define a class inside a function We can instantiate a class inside a function but not define ? What could be the cause of such a behavior? We can define...
4
by: kungfuelmosan | last post by:
Hey guys, Im just getting into c++ at the moment so please bare with me Basically i need to declare a vector<stringstringArray(50) inside a class, however by doing so i am getting the following...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.