Hi,
I have a little problem with nested classes :
The code is:
Code:
#include<iostream.h>
class outside
{
public:
int age;
public:
outside( int age )
{
this->age = age;
}
void show_outside() {
cout<<"Age="<<this->age;
}
class inside : public outside
{
int salary;
public:
inside( int salary)
{
this->salary = salary;
}
void show_inside() {
cout<< "Salary="<<this->salary<<this->age;
}
};
};
int main()
{
outside a( 45 ) ;
outside::inside b( 23 ) ;
a.show_outside();
b.show_inside();
}
I am getting the following errors:
nestedclasses.cpp:19: error: invalid use of incomplete type ‘class outside’
nestedclasses.cpp:4: error: forward declaration of ‘class outside’
nestedclasses.cpp: In member function ‘void outside::inside::show_inside()’:
nestedclasses.cpp:29: error: ‘class outside::inside’ has no member named ‘age’
I think the problem is the way I am inheriting the class outside.....
Can any body suggest me the sol. ??
Thanks