- Joined
- 5/14/07
- Messages
- 85
- Points
- 16
Quick question for those of you who are more knowledgeable in C++...
Let's say I have a two classes:
Because SuperMatrix contains a pointer, it's going to need an explicitly defined copy constructor, destructor, and assignment operator. The copy constructor and destuctor are easy. The problem is the assignment operator.
How do I do this? The lhs needs the new rhs _rows and _columns values, but the operator procedure will have no ability to copy them over because they are private to the base Matrix class. (I cannot -- will not -- change this.) I'm sure there's something obvious I'm overlooking. Help!
Let's say I have a two classes:
Code:
class Matrix
{
private:
[INDENT]int _rows;
int _columns;
[/INDENT]};
class SuperMatrix : public Matrix
{
public:
[INDENT]SuperMatrix(const SuperMatrix& sm2);
const SuperMatrix operator=(const SuperMatrix& rhs);
~SuperMatrix();
[/INDENT]private:
[INDENT]double* _m;
[/INDENT]}
Because SuperMatrix contains a pointer, it's going to need an explicitly defined copy constructor, destructor, and assignment operator. The copy constructor and destuctor are easy. The problem is the assignment operator.
How do I do this? The lhs needs the new rhs _rows and _columns values, but the operator procedure will have no ability to copy them over because they are private to the base Matrix class. (I cannot -- will not -- change this.) I'm sure there's something obvious I'm overlooking. Help!