inner class acess

im trying to acess parent class properties from inner class...
but seems nor working

eg:
1
2
3
4
5
6
7
8
9
10
11
class Parent
{
char *Name;
    class Inner
    {
        Inner(Parent& x)
        {
            printf(x.Name);
        };
    };
}

its possible do it?
What do you mean by "not working"? Do you get an error message?
Probably need to put a semicolon at the end of both class declarations, and remove the extraneous semicolon on line 9.
Visual Studio 2012 show this error

error C2512: 'Parent' : no appropriate default constructor available

fullcode
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
class Parent
{
	const char* name;
	class Inner
	{
		Inner(Parent& x)
		{
			std::cout<<x.name;
		}
	}Inner;
}Parent;
int main()
{

	return(0x0);
}

You're attempting to default-construct an object of type Parent, confusingly called "Parent", at global scope

To do that, Parent's default constructor is required. The compiler attempts to generate Parent's default constructor, which attempts to default-construct all members.

Your class Parent has a data member confusingly called "Inner", of type Parent::Inner. The type Parent::Inner has a user-defined constructor which prevents generation of Inner's default constructor, which means Parent's default constructor cannot be compiled either,
i imagined...
well this means which isn't possible to access parent properties?
there are another way?
Last edited on
No, this means that you can't default-construct an object of a class whose default constructor you suppressed.
The smallest change to make this compile is to add public: Inner() {} between lines 6 and 7
Topic archived. No new replies allowed.