|
| ||||||||||
| Tags: global class, local class, object oriented, programming, variable |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| What is the difference between Local class and global class in C++?
|
|
#2
| ||||
| ||||
| Re: What is the difference between Local class and global class in C++?
Well, taking about Local class then a class can be declared or defined inside a function or a block .such classes are known as Local class. When a class is declared within a function then it is known only to that function and unknown outside of it. Local classes have following restrictions. 1) All member function of local class should be defined within the class declaration. 2) The function in which the class is defined cannot access private member of the class directly. 3) The local class cannot use local variables of the functions in which it is declared. |
|
#3
| ||||
| ||||
| Re: What is the difference between Local class and global class in C++? Code: .> For example
#include<iostream.h>
main()
{
class sample
{
int n;
public:
void get_num();
{
cout<<”give no”;
cin>>n;
}
void display()
{
cout<<”the no. is “<<n;
}
}
sample s;
s.get_num();
s.display();
} |
|
#4
| |||
| |||
| Re: What is the difference between Local class and global class in C++?
When a class is defined outside of any function then such classes are known as Global class. All the functions in the program can access global classes. It is completely opposite to local class. In local class it is accessible only to the function where as in global class it is accessible outside the function in the program. One should note that the in global class it is declared or defined outside the class not inside the class, if it is defined inside the class then it will be assumed as neither local class nor global class. |
|
#5
| |||
| |||
| Re: What is the difference between Local class and global class in C++? Code: For example
class Box
{
private : int l,h,w;
public :
void get_data()
{
cout<<”enter the length width and height of box”;
cin>>l>>h>>w;
}
void display()
{
cout<<”the length of box is<<l;
cout<<”the height of box is<<h;
cout<<”the width of box is<<w;
}
};
main ()
{
Box b1,b2;
b1.get_data();
b2.get_data();
b1.display();
b2.display();
} |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "What is the difference between Local class and global class in C++?" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Upgrade Sony Ericsson Xperia Play Micro SD card from class 2 8GB to class 4 32GB | Aaryan2011 | Portable Devices | 8 | 08-10-2011 11:06 PM |
| Debug class and Trace class Difference | Amaresh | Software Development | 5 | 22-01-2010 09:00 AM |
| Difference among concrete class and abstract class | Roxy_jacob | Software Development | 4 | 07-12-2009 12:22 PM |
| What is the Difference between Class and Object? | RupaliP | Software Development | 5 | 28-02-2009 06:03 PM |
| Good news for CBSE CLASS X & CLASS IX - visit learnnext | surya_expert | Education Career and Job Discussions | 0 | 13-12-2008 11:09 AM |