Local Class in C++
In C++, generally a class is declared outside of the main() function, which is global for the program and all functions can access that class i.e. the scope of such class is global.
A local class is declared inside any function (including main() i.e. we can also declare a class within the main() function) and the scope of local class is local to that function only i.e. a local class is accessible within the same function only in which class is declared.
Example:
Here, we are declaring and defining two classes "Test1" and "Test2", "Test1" is declared inside a user-defined function named testFunction() and "Test2" is declares inside the main() function.
Since classes "Test1" and "Test2" are declared within the functions, thus, their scope will be local to those functions. Hence, "Test1" and "Test2" are local classes in C++.
Program:
Output
need an explanation for this answer? contact us directly to get an explanation for this answer