![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Oct 2005
Location: Portugal
Posts: 53
Rep Power: 3
![]() |
Matrix
Hi there again
I have one annoying problem here :eek: I have one class 'CVector': class CVector
{
int *vector;
unsigned n; // this is the number of elements
public:
CVector( );
CVector( unsigned );
virtual ~CVector();
int& operator[] ( const int );
const int& operator[] ( const int ) const;
};And one 'CMatrix' derived from that: class CMatrix : public CVector
{
CVector *matrix;
unsigned lin, col;
string m_sNome;
public:
CMatrix( const string&, const unsigned, const unsigned );
~CMatrix();
CVector& operator[] ( const int );
const CVector& operator[] ( const int ) const;
friend CMatrix operator*( const CMatrix&, const CMatrix& );
};Now in the constructor of CMatrix, i need to reserve dynamic memory for the array of CVector's, but I want each CVector inicialized with 'c' colums so I do this: CMatrix( const string& str, const unsigned l, const unsigned c)
lin( l ), col( c ), m_sNome( str )
{
matrix = new CVector[ l ];
}But if i do this, the each CVector object in the array is not incialized with c colums... How can I do this??? Thanks in advance ![]() |
|
|
|
|
|
#2 |
|
Newbie
Join Date: Nov 2005
Location: Puerto Rico
Posts: 12
Rep Power: 0
![]() |
Let me see..
I only made a fast overview of your code but I can see that you can solve your problem by initializing every CVector object in the matrix object with some loop. Like a for loop .
for (int i =0;i< matrix array size ;i++) {
matrix[i]= new CVector(c);
}That should be in the constructor.
__________________
From P.R. to the World!! RoBeRt Last edited by robrosas; Nov 24th, 2005 at 11:05 AM. Reason: forgot something |
|
|
|
|
|
#3 |
|
Professional Programmer
Join Date: Sep 2005
Location: serbia & montenegro
Posts: 484
Rep Power: 3
![]() |
nice first post..
![]() |
|
|
|
|
|
#4 |
|
Programmer
Join Date: Oct 2005
Location: Portugal
Posts: 53
Rep Power: 3
![]() |
That makes sence :p
I'll try it Thank you very nice ![]() |
|
|
|
|
|
#5 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,198
Rep Power: 5
![]() |
Unrelated to the problem, I know, but what is actually being achieved by deriving CMatrix from CVector?
|
|
|
|
|
|
#6 |
|
Programmer
Join Date: Oct 2005
Location: Portugal
Posts: 53
Rep Power: 3
![]() |
I guess nothing...
|
|
|
|
|
|
#7 |
|
Newbie
Join Date: Nov 2005
Location: Puerto Rico
Posts: 12
Rep Power: 0
![]() |
...
I saw that too grumpy, but he only asked for the constructor problem. Theres no sense why should CMatrix derives from Cvector. CMatrix can simply just "use" a Cvector and that's it.
__________________
From P.R. to the World!! RoBeRt |
|
|
|
|
|
#8 |
|
Programmer
Join Date: Oct 2005
Location: Portugal
Posts: 53
Rep Power: 3
![]() |
Ye you are right
![]() |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|