Thread: scope resolution operator ::: ??

  1. #1
    Normal vector Carlos's Avatar
    Join Date
    Sep 2001
    Location
    Budapest
    Posts
    463

    scope resolution operator ::: ??

    Hi!
    I've found a weird thing.
    I typed 3x ":" after the class name by mistake, and the code completion (VC++ 6.0) drop-down list offered me some functions..
    Just try it out!

    Type e.g. CString::: in a cpp file and see what happens!
    So, the ::: is also a scope operator?

    P.s.
    :::: doesn't work

  2. #2
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    it jumps back to global space.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  3. #3
    Normal vector Carlos's Avatar
    Join Date
    Sep 2001
    Location
    Budapest
    Posts
    463
    Yes, FillYourBrain, you're right, but why did MS implement such things? Does someone use this "feature"?

  4. #4
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571

    Re: scope resolution operator ::: ??

    Originally posted by Carlos
    Hi!
    I've found a weird thing.
    I typed 3x ":" after the class name by mistake, and the code completion (VC++ 6.0) drop-down list offered me some functions..
    Just try it out!

    Type e.g. CString::: in a cpp file and see what happens!
    So, the ::: is also a scope operator?

    P.s.
    :::: doesn't work
    Actually the scope resolution operator is only 2 colons. So it looks like this :: . You can use it to clear up ambigiouty in derived classes with the same member function names if you don't declare them as virtual. They have many more uses as well.

  5. #5
    Normal vector Carlos's Avatar
    Join Date
    Sep 2001
    Location
    Budapest
    Posts
    463
    I know what's the purpose of the scope operator ::, MrWizard, what about this :::?

    It jumps back to global space (thanks FillYourBrain), just can't understand why was it implemented by MS?

    I think it's just a bug

    VC's editor is looking for the last pair of colons when it tries to complete your code.

    So, when you type
    CString:::

    the CString: is not taken in account, only ::, which is indeed the global space.

    P.s.
    Hope the compiler doesn't have such features :°].

  6. #6
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    honestly I don't know if that's standard C++. I would assume that there really isn't any need to ever use it. Maybe someone else knows of a reason.

    edit: a quick look through the official spec doesn't seem to mention it.
    Last edited by FillYourBrain; 10-01-2002 at 11:50 AM.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  7. #7
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    Code:
    #include <iostream>
    using namespace std;
    
    int foo;
    
    int main(void)
    {     int foo;
          ::foo=4;
          foo=5;
          cout<<"Global variable foo: "<<::foo;
          cout<<"Local foo: "<<foo;
          return 0;
    }
    I think that should compile at least.

  8. #8
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Must be MS specific. Bloodshed Dev-C++ just whines about the parse error...
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

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, 08:18 PM
  2. Smart pointer class
    By Elysia in forum C++ Programming
    Replies: 63
    Last Post: 11-03-2007, 07:05 AM
  3. How to avoid typing std:: (scope resolution operator)
    By Sharan in forum C++ Programming
    Replies: 9
    Last Post: 04-30-2006, 08:25 PM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  5. Nested loop frustration
    By caroundw5h in forum C Programming
    Replies: 14
    Last Post: 03-15-2004, 09:45 PM