CodeClerks

LOCAL CLASSES IN C++



Write the reason you're deleting this FAQ

LOCAL CLASSES IN C++

Classes can be defined and used inside afunction or a block. Such classes are called local classes.



Examples:

void test (int a) // function

{

………….

………….

class student // localclass

{

…………

………… // classdefinition

…………

};

……….

……….

student s1(a); // create student object

………. // use student object

}



Local classes can use global variables (declared above the function) andstatic variables declared inside the function but cannot use automatic local
variables. The global variables should be used with the scope operator (:LOCAL CLASSES IN C++.


There are some restrictions inconstructing local classes. They cannot have static data

Members and member functions must bedefined inside the local classed. Enclosing function cannot access the private
members of a local class. However, we can achieve this by declaring the
enclosing function as a friend.

Comments

Please login or sign up to leave a comment

Join