By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,804 Members | 1,634 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,804 IT Pros & Developers. It's quick & easy.

inheritance

P: n/a
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.
Jul 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

"Brett Irving" <ba*****@hotmail.com> wrote in message
news:4f*************************@posting.google.co m...
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
Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.