What is a scope operator?

This is a discussion on What is a scope operator? within the C++ Programming forums, part of the General Programming Boards category; What is a scope operator?...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    30

    What is a scope operator?

    What is a scope operator?

  2. #2
    Unregistered
    Guest

    ::

    its the 2 colons next to each other. when you define a class member function its like this:

    Code:
    void myclass::myfunction( )
    {
    blah;
    blah;
    blah;
    }
    the :: indicates that myfunction is limited to being used by instances of myclass.

    Also if you have a global and local identifier it can be used to distinguish them:

    Code:
    int var = 10;
    
    void main( )
    {
         int var = 20;
         cout << "global variable = "  << ::var << endl;    //prints 10
         cout << "local variable = " << var << endl;        //prints 20
    }
    Hope that helps....

  3. #3
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    Also, you can access member functions of a class without declaring an object of that class (Like ios::binary), provided they're declared as static of course.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 09:18 PM
  2. Smart pointer class
    By Elysia in forum C++ Programming
    Replies: 63
    Last Post: 11-03-2007, 08:05 AM
  3. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 11:03 AM
  4. Nested loop frustration
    By caroundw5h in forum C Programming
    Replies: 14
    Last Post: 03-15-2004, 09:45 PM
  5. operator overloading and dynamic memory program
    By jlmac2001 in forum C++ Programming
    Replies: 3
    Last Post: 04-07-2003, 12:51 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21