Create Objects

class a
{
private:
class b
{
private:
int c;
public:
void display()
{
cout<<c;
}
};
public:
void input();
};

Can we create an object for class b in main() function? If possible how?
you cant define a class inside a definition of another class.. that code above should generate an error or something..

edit: im wrong sorry
Last edited on
No I didnt get any error.....It is possible to create nested classes.
it is possible to create an object in the main function
main()
{
a :: b b1,b2
...
....


.....
}
b1 and b2 objects of class b
Wow, every response in the thread has been wrong so far.

You can define a class inside another class.

You cannot instantiate b directly in main() only because b is declared private in a.
If b were declared public in a, then amit0991's response would be right.
good thing I deleted my post ^^, I too said you could make an object of it, until I reread it was private and then wasn't sure so hit the delete button.
Topic archived. No new replies allowed.