help with derived class

Suppose I have a class like the following:
class IntegerSet
{
private:
int *set; // dynamically allocated set
int size;
bool validEntry( int x ) const { return x >= 0 && x < size; }
};

and then I have a class like:

class array: public IntegerSet
{
public: array operator +(array one);
array operator -(array one);
array operator /(array one);
array operator *(array one);
array operator %(array one);
array operator =(array one);
private: int MaxSize;
};

If in the original class, IntegerSet, the constructor creates an array of sets, and the new class (array) overloads the mathematical operators, how would I access the private members of class IntegerSet in the public member functions of class array? I can't figure out how to access them to overload them! Please help!!! This is due Tuesday night!!

Comments

  • : Suppose I have a class like the following:
    : class IntegerSet
    : {
    : private:
    : int *set; // dynamically allocated set
    : int size;
    : bool validEntry( int x ) const { return x >= 0 && x < size; }
    : };
    :
    :
    : class array: public IntegerSet
    : {

    [...snip...]

    how would I access the private members of class IntegerSet in the public member functions of class array?

    You can't. It's private property (keep out, trespassers will be shot on sight). If you want derived classes to have access to members, make them protected. This hides them from everyone but your subclasses.

    Cheers,
    Eric
  • : You can't. It's private property (keep out, trespassers will be shot on sight). If you want derived classes to have access to members, make them protected. This hides them from everyone but your subclasses.

    Would it work if I used an object of type IntegerSet within the private section of the class array? Would I then be able to do it?
    :
    : Cheers,
    : Eric
    :

  • : Would it work if I used an object of type IntegerSet within the private section of the class array? Would I then be able to do it?

    Make them protected:
    [code=ffffff]
    [color=000080]class[/color] Stuff {
    [color=000000][b]public[/b][/color]:
    [color=80a0b0][italic]// visible to everyone[/italic][/color]
    [color=000000][b]protected[/b][/color]:
    [color=80a0b0][italic]// visible to ourself and base classes[/italic][/color]
    [color=000000][b]private[/b][/color]:
    [color=80a0b0][italic]// visible only to ourself[/italic][/color]
    };
    [/code]
    Cheers,
    Eric


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories