inheritance

Discussion in 'C++' started by Brett Irving, Jun 29, 2003.

  1. Brett Irving

    Brett Irving Guest

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

    however it keeps coming up with

    CheckMyArray.cpp: In method `CheckMyArray::CheckMyArray(int)':
    CheckMyArray.cpp:6: no matching function for call to `InitMyArray::InitMyArray ()'
    InitMyArray.h:15: candidates are: InitMyArray::InitMyArray(int)
    InitMyArray.h:16: InitMyArray::InitMyArray(int, int)
    InitMyArray.h:25: InitMyArray::InitMyArray(const InitMyArray &)
    make: *** [CheckMyArray] Error 1

    My code for Init and Check is

    //child class of InitMyArray

    #ifndef CHECKMYARRAY_H
    #define CHECKMYARRAY_H

    #include "InitMyArray.h"

    class CheckMyArray : public InitMyArray
    {
    private:

    int cVal;

    public:

    CheckMyArray(int);

    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.
    Brett Irving, Jun 29, 2003
    #1
    1. Advertising

  2. "Brett Irving" <> wrote in message
    news:...
    > I am trying to define an inherited class CheckMyArray
    > which inherits from InitMyArray
    >
    > however it keeps coming up with
    >
    > CheckMyArray.cpp: In method `CheckMyArray::CheckMyArray(int)':
    > CheckMyArray.cpp:6: no matching function for call to

    `InitMyArray::InitMyArray ()'
    > InitMyArray.h:15: candidates are: InitMyArray::InitMyArray(int)
    > InitMyArray.h:16: InitMyArray::InitMyArray(int, int)
    > InitMyArray.h:25: InitMyArray::InitMyArray(const

    InitMyArray &)
    > make: *** [CheckMyArray] Error 1
    >
    > My code for Init and Check is
    >
    > //child class of InitMyArray
    >
    > #ifndef CHECKMYARRAY_H
    > #define CHECKMYARRAY_H
    >
    > #include "InitMyArray.h"
    >
    > class CheckMyArray : public InitMyArray
    > {
    > private:
    >
    > int cVal;
    >
    > public:
    >
    > CheckMyArray(int);
    >
    > 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.


    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::CheckMyArray(int size) : InitMyArray(size)
    {
    ...
    }

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

    john
    John Harrison, Jun 29, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. maxw_cc
    Replies:
    1
    Views:
    3,117
    Martijn van Steenbergen
    Dec 21, 2003
  2. cppsks
    Replies:
    0
    Views:
    803
    cppsks
    Oct 27, 2004
  3. karthikbalaguru
    Replies:
    9
    Views:
    1,025
  4. Daniel Pitts
    Replies:
    27
    Views:
    1,873
    Mike Schilling
    Feb 27, 2008
  5. johnsonlau
    Replies:
    1
    Views:
    760
    Kai-Uwe Bux
    Jul 21, 2008
Loading...

Share This Page