It's not clear what you are trying to do. But there needs to be something in the outer class constructor to provide the value for the inner class constructor. Here is my guess at what you might be looking for:
Code:
class one
{
int xvalue;
public:
one(int outer_value, int inner_value)
:
xvalue( outer_value ),
obj1( inner_value )
{}
class nestedone
{
int ivalue;
public:
nestedone( int value )
:
ivalue( value )
{}
void function();
}obj1;
};
void one::nestedone::function()
{
cout<<"Iam in nestedone function\n";
}
int main(void)
{
one obj(1, 2);
obj.obj1.function();
return 0;
}
In case you haven't seen the member initialization syntax of C++ before, I'll give a short explanation. This code:
Code:
nestedone( int value )
:
ivalue( value )
{}
behaves the save as this code:
Code:
nestedone( int value )
{
ivalue = value;
}
Either works equally well for that constructor, so changing that constructor was just a matter of coding style.
But in the outer constructor, using the member initialization syntax was more important. Once nestedone's constructor is defined such that the parameter is required, the outer constructor must initialize obj1
before the opening "{" of its body.