Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > inheritance

Reply
Thread Tools

inheritance

 
 
Brett Irving
Guest
Posts: n/a
 
      06-29-2003
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.
 
Reply With Quote
 
 
 
 
John Harrison
Guest
Posts: n/a
 
      06-29-2003

"Brett Irving" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ Struct inheritance against class inheritance johnsonlau C++ 1 07-21-2008 04:58 PM
Interface inheritance vs Implementation inheritance. Daniel Pitts Java 27 02-27-2008 01:37 AM
Private Inheritance and Publice Inheritance karthikbalaguru C++ 9 09-10-2007 01:05 PM
mul. inheritance & overloading operator new/delete solved by virtual base inheritance? cppsks C++ 0 10-27-2004 07:49 PM
Private access modifier and Inheritance (Inheritance implementation in Java) maxw_cc Java 1 12-21-2003 11:38 AM



Advertisments