Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 24th, 2005, 9:59 AM   #1
-=PARADOX=-
Programmer
 
-=PARADOX=-'s Avatar
 
Join Date: Oct 2005
Location: Portugal
Posts: 53
Rep Power: 3 -=PARADOX=- is on a distinguished road
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
-=PARADOX=- is offline   Reply With Quote
Old Nov 24th, 2005, 11:04 AM   #2
robrosas
Newbie
 
robrosas's Avatar
 
Join Date: Nov 2005
Location: Puerto Rico
Posts: 12
Rep Power: 0 robrosas is an unknown quantity at this point
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
robrosas is offline   Reply With Quote
Old Nov 24th, 2005, 11:17 AM   #3
ivan
Professional Programmer
 
ivan's Avatar
 
Join Date: Sep 2005
Location: serbia & montenegro
Posts: 482
Rep Power: 3 ivan is on a distinguished road
nice first post..
ivan is offline   Reply With Quote
Old Nov 24th, 2005, 3:16 PM   #4
-=PARADOX=-
Programmer
 
-=PARADOX=-'s Avatar
 
Join Date: Oct 2005
Location: Portugal
Posts: 53
Rep Power: 3 -=PARADOX=- is on a distinguished road
That makes sence :p

I'll try it

Thank you very nice
-=PARADOX=- is offline   Reply With Quote
Old Nov 25th, 2005, 3:48 AM   #5
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,192
Rep Power: 5 grumpy is on a distinguished road
Unrelated to the problem, I know, but what is actually being achieved by deriving CMatrix from CVector?
grumpy is offline   Reply With Quote
Old Nov 25th, 2005, 4:53 AM   #6
-=PARADOX=-
Programmer
 
-=PARADOX=-'s Avatar
 
Join Date: Oct 2005
Location: Portugal
Posts: 53
Rep Power: 3 -=PARADOX=- is on a distinguished road
I guess nothing...
-=PARADOX=- is offline   Reply With Quote
Old Nov 25th, 2005, 8:42 AM   #7
robrosas
Newbie
 
robrosas's Avatar
 
Join Date: Nov 2005
Location: Puerto Rico
Posts: 12
Rep Power: 0 robrosas is an unknown quantity at this point
...

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
robrosas is offline   Reply With Quote
Old Nov 25th, 2005, 8:46 AM   #8
-=PARADOX=-
Programmer
 
-=PARADOX=-'s Avatar
 
Join Date: Oct 2005
Location: Portugal
Posts: 53
Rep Power: 3 -=PARADOX=- is on a distinguished road
Ye you are right
-=PARADOX=- is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 8:16 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC