any idea????

(.text+0x8b): undefined reference to `TwoD::TwoD()'
P.cpp:(.text+0x122): undefined reference to `TwoD::TwoD(int, int)'
P.cpp:(.text+0x12d): undefined reference to `TwoD::~TwoD()'
P.cpp:(.text+0x149): undefined reference to `TwoD::~TwoD()'
P.cpp:(.text+0x15f): undefined reference to `TwoD::~TwoD()'
collect2: ld returned 1 exit status


in the main function

int main()
{
TwoD Twda; // Declaring the three TwoD objects containing


int r, c;

cout << "How many rows will be in your arrays?" << endl;
cin >> r;
cout << endl << "How many columns will be in your arrays?" << endl;
cin >> c;

TwoD(xRows, yCols); // Creating the arrays


return 0;
}

 
TwoD(xRows, yCols); // Creating the arrays  


This isn't correct. What you meant to say was Twda(r, c); // Creating the arrays which is the object of class TwoD passing the r and c variables as arguments. Also make sure your including your header files correctly in both your main and class implementation files.
Last edited on
Hi
I still have the errors!!!!!???? I do no know becouse I did the sugestions I post the constructor
P.cpp:(.text+0x9b): undefined reference to `TwoD<float>::TwoD(int, int)'
P.cpp:(.text+0xb6): undefined reference to `TwoD<float>::print(int, int)'
P.cpp:(.text+0xd2): undefined reference to `TwoD<float>::~TwoD()'
P.cpp:(.text+0xe8): undefined reference to `TwoD<float>::~TwoD()'
collect2: ld returned 1 exit status
--------------------------------------------------------------------
the constructor is
TwoD<T>::TwoD( int x, int y)
{
r = x;

c = y;

elet = new int *[r];

for (int i = 0; i < r; i++){

elet[i] = new int [c];

}
for (int i=0; i < r; i++){

for(int j=0; j < c; j++){

elet[i][j] = i*j;
}
}
}
--------------------------------------------------------
the min is

int main()

{

TwoD<float> D(3,4);


D.print( 3,4 );

return 0;
}
If TwoD is a template class, then you need to move the implementation of TwoD's methods to the TwoD header file.
I have done before in the implementation in separate file and work fine I do not know what going on???????

in every function I put right on the top the template <class T> and work fine.
Topic archived. No new replies allowed.