473,803 Members | 3,619 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.
Jul 19 '05 #1
1 4517

"Brett Irving" <ba*****@hotmai l.com> wrote in message
news:4f******** *************** **@posting.goog le.com...
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.


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
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4382
by: AIM | last post by:
Error in msvc in building inheritance.obj to build hello.pyd Hello, I am trying to build the boost 1.31.0 sample extension hello.cpp. I can not compile the file inheritance.cpp because the two files containing some templates: adjacency_list.hpp and mem_fn.hpp can not compile. Does anyone have any solutions?
2
4339
by: Graham Banks | last post by:
Does using multiple inheritance introduce any more performance overhead than single inheritance?
4
2902
by: JKop | last post by:
I'm starting to think that whenever you derive one class from another, that you should use virtual inheritance *all* the time, unless you have an explicit reason not to. I'm even thinking that there shouldn't have been a "virtual" keyword for this purpose, but instead, a "nonvirtual" keyword! In teaching inheritance, you see the common example: class Vehicle {}
5
2183
by: Morgan Cheng | last post by:
It seems no pattern defined by GoF takes advantage of multiple inheritance. I am wondering if there is a situation where multiple inheritance is a necessary solution. When coding in C++, should multiple inheritance still be avoided? If yes, why multiple inheritance is introducted into C++?
10
2666
by: davidrubin | last post by:
Structural inheritance (inheriting implementation) is equivalent to composition in that a particular method must either call 'Base::foo' or invoke 'base.foo'. Apparantly, The Literature tells us to prefer composition over inheritance. Can anyone provide some reasons why this is the case (based on "real-world" experience)? For example, is structural inheritance more difficult to maintain? More difficult to test? Have a larger impact on...
14
12924
by: Steve Jorgensen | last post by:
Recently, I tried and did a poor job explaining an idea I've had for handling a particular case of implementation inheritance that would be easy and obvious in a fully OOP language, but is not at all obvious in VBA which lacks inheritance. I'm trying the explanation again now. I often find cases where a limited form of inheritance would eliminate duplication my code that seems impossible to eliminate otherwise. I'm getting very...
22
23388
by: Matthew Louden | last post by:
I want to know why C# doesnt support multiple inheritance? But why we can inherit multiple interfaces instead? I know this is the rule, but I dont understand why. Can anyone give me some concrete examples?
45
6369
by: Ben Blank | last post by:
I'm writing a family of classes which all inherit most of their methods and code (including constructors) from a single base class. When attempting to instance one of the derived classes using parameters, I get CS1501 (no method with X arguments). Here's a simplified example which mimics the circumstances: namespace InheritError { // Random base class. public class A { protected int i;
60
4950
by: Shawnk | last post by:
Some Sr. colleges and I have had an on going discussion relative to when and if C# will ever support 'true' multiple inheritance. Relevant to this, I wanted to query the C# community (the 'target' programming community herein) to get some community input and verify (or not) the following two statements. Few programmers (3 to7%) UNDERSTAND 'Strategic Functional Migration
6
3830
by: Bart Simpson | last post by:
I remember reading on parashift recently, that "Composition is for code reuse, inheritance is for flexibility" see (http://www.parashift.com/c++-faq-lite/smalltalk.html#faq-30.4) This confused me somewhat as I have always thought you get code reuse "for free" with inheritance. Am I missing something?. Will someone care to explain ??
0
9703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9566
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10555
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10300
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10069
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9127
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6844
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2974
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.