Hi All,
We can not access the data member of a class nested with in another class.It does not get instantiated also.So what are the use of having a class nested with in another class?
Thanks and Regards,
A
Printable View
Hi All,
We can not access the data member of a class nested with in another class.It does not get instantiated also.So what are the use of having a class nested with in another class?
Thanks and Regards,
A
You can access the data, depending on whether it is visible from whatever scope you're in. I'm not sure what you mean by "it does not get instantiated".
If I'm understanding you, you mean something like std::list<T>::iterator ? Post some code, and we can hammer out any errors or troubles you might be having.
The only change of a nested class is that it will be located inside the first class.
class A { class B {}; };
To create class B, you will need to do A::B someth;
What's the use? Consider if the class is only supposed to be use by the class it resides in, or if it makes sense to access it via A::B.
For example, in a linked list container, it makes sense to make the list node an inner class, because no one else has any business accessing that class.
Nesting classes and structs within classes normally shows ownership. I don't do it very often.