inheritance

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Brett Irving

    #1

    inheritance

    I am trying to define an inherited class CheckMyArray
    which inherits from InitMyArray

    however it keeps coming up with

    CheckMyArray.cp p: In method `CheckMyArray:: CheckMyArray(in t)':
    CheckMyArray.cp p:6: no matching function for call to `InitMyArray::I nitMyArray ()'
    InitMyArray.h:1 5: candidates are: InitMyArray::In itMyArray(int)
    InitMyArray.h:1 6: InitMyArray::In itMyArray(int, int)
    InitMyArray.h:2 5: InitMyArray::In itMyArray(const InitMyArray &)
    make: *** [CheckMyArray] Error 1

    My code for Init and Check is

    //child class of InitMyArray

    #ifndef CHECKMYARRAY_H
    #define CHECKMYARRAY_H

    #include "InitMyArra y.h"

    class CheckMyArray : public InitMyArray
    {
    private:

    int cVal;

    public:

    CheckMyArray(in t);

    void put(int, int);

    };

    #endif


    #ifndef INITMYARRAY_H
    #define INITMYARRAY_H

    #include "MyArray.h"

    class InitMyArray
    {
    private:

    int arrSize;
    int arrVal;

    public:
    /*constructors*/
    InitMyArray(int );
    InitMyArray(int , int);

    /*Destructors*/
    ~InitMyArray();

    /*member functions*/
    int get(int);

    int getSize();
    };

    #endif



    please help, Im cant seem to figure this out.
  • John Harrison

    #2
    Re: inheritance


    "Brett Irving" <balgorg@hotmai l.com> wrote in message
    news:4f68b81.03 06290320.2de5ac 44@posting.goog le.com...[color=blue]
    > I am trying to define an inherited class CheckMyArray
    > which inherits from InitMyArray
    >
    > however it keeps coming up with
    >
    > CheckMyArray.cp p: In method `CheckMyArray:: CheckMyArray(in t)':
    > CheckMyArray.cp p:6: no matching function for call to[/color]
    `InitMyArray::I nitMyArray ()'[color=blue]
    > InitMyArray.h:1 5: candidates are: InitMyArray::In itMyArray(int)
    > InitMyArray.h:1 6: InitMyArray::In itMyArray(int, int)
    > InitMyArray.h:2 5: InitMyArray::In itMyArray(const[/color]
    InitMyArray &)[color=blue]
    > make: *** [CheckMyArray] Error 1
    >
    > My code for Init and Check is
    >
    > //child class of InitMyArray
    >
    > #ifndef CHECKMYARRAY_H
    > #define CHECKMYARRAY_H
    >
    > #include "InitMyArra y.h"
    >
    > class CheckMyArray : public InitMyArray
    > {
    > private:
    >
    > int cVal;
    >
    > public:
    >
    > CheckMyArray(in t);
    >
    > void put(int, int);
    >
    > };
    >
    > #endif
    >
    >
    > #ifndef INITMYARRAY_H
    > #define INITMYARRAY_H
    >
    > #include "MyArray.h"
    >
    > class InitMyArray
    > {
    > private:
    >
    > int arrSize;
    > int arrVal;
    >
    > public:
    > /*constructors*/
    > InitMyArray(int );
    > InitMyArray(int , int);
    >
    > /*Destructors*/
    > ~InitMyArray();
    >
    > /*member functions*/
    > int get(int);
    >
    > int getSize();
    > };
    >
    > #endif
    >
    >
    >
    > please help, Im cant seem to figure this out.[/color]

    When you construct a CheckMyArray an InitMyArray has to be constucted first.
    That is because CheckMyArray inherits from InitMyArray. To construct an
    InitMyArray one of its constructors must be invoked. By default what happens
    is that the default constructor gets invoked, but InitMyArray doesn't have
    one, that is what the error message says.

    Its hard to be certain from the code you've posted but probably you want to
    do something like this

    ChemMyArray::Ch eckMyArray(int size) : InitMyArray(siz e)
    {
    ...
    }

    Now you are invoking the InitMyArray(int ) constructor using the int
    parameter for the CheckMyArray constructor.

    john


    Comment

    Working...