Child class and Parent class
i'm calling function "output" from other classes to other classes as you can see below but i'm receiving errors on line 21,32,44
please checkout :-)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
#include<iostream>
using namespace std;
class human
{
public:
void output()
{
cout << "human" << endl;;
}
};
class man :human
{
public:
void output()
{
human::output;
cout << "Man" << endl;
}
};
class woman :human
{
public:
void output()
{
man::output;
cout << "Women" << endl;
}
};
class chakka :man
{
public:
void output()
{
human::output;
cout << "chakka" << endl;
}
};
void main()
{
human h1;
man m1;
woman w1;
chakka c1;
h1.output();
m1.output();
w1.output();
c1.output();
}
| |
but i'm receiving errors on line 21,32,44 |
What exactly are the errors?
Do you know that when you don't specify the access specifier in classes you get private by default.
And in C++ main must be defined to return an int, and you should return an int from this function:
1 2 3 4 5
|
int main()
{
return 0;
}
| |
Lines 21,32,44: Those are not valid function calls. To call a function, you need ().
Line 32: woman does not inherit from man. You can't call man::output(). Did you mean human::output()?
Line 44: chakka inherits from man. Did you intend to call man::output()?
Topic archived. No new replies allowed.