What is Nested Class ? How Can We Define and Declare Nested Classes ?
Nested Class :- Classes can be defined inside other classes. Classes that are defined inside other classes are called nested classes. A class can be nested in every part of the surrounding class, in the public, protected and private section. Such a nested class can be considered a member of the surrounding class. The normal access and visibility riles in classes apply to nested classes.
Example :-
class surround
{
public:
class firstwithin
{
public:
firstwithin ();
int getvar () const
{
return (variable);
}
private:
class secondwithin
{
public:
secondwithin ();
int getvar () const
{
return (variable);
}
private:
int variable;
};
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment