Could use some help...:)

From: Silver (argytzak_at_med.auth.gr)
Date: 12/27/03


Date: Sat, 27 Dec 2003 01:38:40 +0200

First of all...merry christmas everyone!

Now, I have to write a program. Among other things, I need to overload the
'*' operator, so that it returns a pointer-to-ponter of type int, which is
intended to contain a 2d array.
Now, I have 2 classes, as follows:
class A

{

    protected:

            int n; // It's the size of a nxn matrix. Is read from the
keyboard in the constructor

            int **p; // memory is dynamically allocated so that p can be
used as an nxn array

    public:

            A() { } // Default constructor

             A(int x); // Constructor with argument

            ~A(); // Destructor

};

class B: public A // INHERITANCE

{

    private:

            int k; // size for a kxk array. Is read form the keyboard in the
constructor

            int **d; // memory is dynamically allocated so that d can be
used as an kxk array

    public:

            B(int y);

            ~B();

};

In the constructor definitions, I allocate memory dynamically, plus I read
the values for the array. In the main program, 2 objects are created :

A a;

B b;

What I am supposed to do, is use the overloaded operator in main(), so that
b.d contains the product of a.p * b.p. ( the funny thing is that a.p*b.p is
nxn array while b.d is an kxk array!! )

I am having some difficulties as to where to define the overloaded operator:

---as a member of class A?

---as a member of class B?

---friend perhaps?

cause whatever I try, I keep getting the error that I cannot access some
class member. The last thing I tried was defining accessors in each class
( get_d, get_p etc) which looked very silly. It compiled, but I got a
run-time error :)

Could someone advise me on how to implement the overloading ?

PS. Using VS .NET

Thanks in advance!



Relevant Pages

  • Re: Error using ==> class
    ... varargin because varargin apparently does not actually allow nargin == ... the change, no changes to code are made, and the constructor (as seen ... All instances of an object must have the same member names in the same ... but I will continue to overload the size method for the ...
    (comp.soft-sys.matlab)
  • Re: A good data structure to store INI files.
    ... },{#Second Ship ... But I would need overload for that, and I could save it into an array for the order and a hash for quick lookup. ...
    (comp.lang.perl.misc)
  • RE: Error MSDAAB ExecuteDataset
    ... SqlHelper.ExecuteDataSet method to execute a stored procedure which fills a ... It is an object array. ... it is calling this overload: ... you turn in on in the project setting page, you will see the error for ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: [C++] Char pointers for memory blocks
    ... > Array a; ... > This translates to (the compiler translates this to): ... >> So lets say we want to overload the array subscript operator and make ... > that you need both he const and non-const version. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: [C++] Char pointers for memory blocks
    ... >> Why MUST you declare an assignement operator overload function AND a ... >> overloading the assignment operator do? ... > class Array{ ... So lets say we want to overload the array subscript operator and make the ...
    (alt.comp.lang.learn.c-cpp)