473,387 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Initializing inherited protected Members of superclass


I have the following program. It has two classes Species and its sub
class NajaNaja. Now I am trying to do this,

The following gives me an error.

NajaNaja::NajaNaja(int age, int weight, KINDOF KINDOF): Species(age),
TypeOf(KINDOF), Heavy(weight)
{
std::cout << "NajaNaja(int, int, KINDOF) constructor...\n";
}

The following works if I do

NajaNaja::NajaNaja(int age, int weight, KINDOF KINDOF): Species(age),
TypeOf(KINDOF)
{
Heavy = weight;
std::cout << "NajaNaja(int, int, KINDOF) constructor...\n";
}
Why is there such a restriction ?
## PROGRAM BEGIN ###

#include <iostream>

enum KINDOF { COBRA, PYTHON, RATTLESNAKE };

class Species
{
public:
// constructors
Species();
Species(int age);
~Species();

//accessors
int HowOld() const { return Age; }
void SetOld(int age) { Age = age; }
int GetWeight() const { return Heavy; }
void SetWeight(int weight) { Heavy = weight; }

//Other methods
void Hiss() const { std::cout << "Species sound!\n"; }
void Snore() const { std::cout << "shhh. I'm Snoreing.\n"; }

protected:
int Age;
int Heavy;
};

class NajaNaja : public Species
{
public:
// Constructors
NajaNaja();
NajaNaja(int age);
NajaNaja(int age, int weight);
NajaNaja(int age, KINDOF kindof);
NajaNaja(int age, int weight, KINDOF kindof);
~NajaNaja();

// Accessors
KINDOF GetKINDOF() const { return TypeOf; }
void SetKINDOF(KINDOF kindof) { TypeOf = kindof; }

// Other methods
void WagTail() { std::cout << "Tail wagging...\n"; }
void BegForFood() { std::cout << "Begging for food...\n"; }

private:
KINDOF TypeOf;
};

Oct 7 '07 #1
0 1361

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

Similar topics

50
by: Dan Perl | last post by:
There is something with initializing mutable class attributes that I am struggling with. I'll use an example to explain: class Father: attr1=None # this is OK attr2= # this is wrong...
5
by: Christian Meier | last post by:
Hi dear programmers I looked for the difference between private and protected inheritance, but couldn't find anything. Here is my sample code: #include <iostream> using std::cout; using...
7
by: Tron Thomas | last post by:
Under the right compiler the following code: class Base { public: virtual void Method(int){} }; class Derived: public Base {
1
by: Dave | last post by:
Hello NG, Regarding access-declarations and member using-declarations as used to change the access level of an inherited base member... Two things need to be considered when determining an...
5
by: Earl Teigrob | last post by:
Is there a way to rename the public properties of a inherited class? I am inheriting an asp.net control (class) and am adding addtional functionality. (in this case, up to 3 borders on an...
4
by: Xavier Décoret | last post by:
I have just come across the following fact. Names defined in a template superclass of the current template must be qualified as being from the superclass. Alternatively, you can also qualify...
5
by: Shak | last post by:
Hi all. I was led to believe that static methods were not inherited by their subclasses (and since that makes sense, rightly so). However, a subclass I've written is using it's (abstract)...
14
by: lovecreatesbea... | last post by:
Could you tell me how many class members the C++ language synthesizes for a class type? Which members in a class aren't derived from parent classes? I have read the book The C++ Programming...
3
by: Ryan Liu | last post by:
Hi, If I extend a user control, do I need to so something for its resource file, like ImageList used in parent class? I ask this question because I often get inconsistent problem with images...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.