Results 1 to 5 of 5

Thread: What is the difference between Local class and global class in C++?

  1. #1
    Join Date
    Dec 2010
    Posts
    16

    What is the difference between Local class and global class in C++?

    Hey Guys, well I am confused between the terms of object oriented programming. If I am not wrong then C++ is also an object oriented programming language. I am having problem in Local class and Global class. Can anybody let me know what are the differences between Local class and global class in C++? So, if anyone having any clue or information about this query then please let me know.

  2. #2
    Join Date
    May 2009
    Posts
    637

    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. #3
    Join Date
    May 2009
    Posts
    527

    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();
    }
    This is an example of local class where in you will find that how class is defined or declared inside the function. You can notice that if a local class is declared to the function then it will only be available to that function only, it won’t available outside the function. This is the specialty of local class where in it is accessible only to the function not outside the function.

  4. #4
    Join Date
    May 2009
    Posts
    543

    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. #5
    Join Date
    May 2009
    Posts
    511

    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();
    }
    This is an example of Global class. Over here you will find that global class is defined outside the function where as previously in local class it was defined in the function itself. This is only the major difference between the local and global class. I think you might be now cleared with the concept of global class and local class.

Similar Threads

  1. Replies: 8
    Last Post: 08-10-2011, 11:06 PM
  2. Debug class and Trace class Difference
    By Amaresh in forum Software Development
    Replies: 5
    Last Post: 22-01-2010, 10:00 AM
  3. Difference among concrete class and abstract class
    By Roxy_jacob in forum Software Development
    Replies: 4
    Last Post: 07-12-2009, 01:22 PM
  4. What is the Difference between Class and Object?
    By RupaliP in forum Software Development
    Replies: 5
    Last Post: 28-02-2009, 07:03 PM
  5. Good news for CBSE CLASS X & CLASS IX - visit learnnext
    By surya_expert in forum Education Career and Job Discussions
    Replies: 0
    Last Post: 13-12-2008, 12:09 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,632,890.24593 seconds with 17 queries