whats the differnce between dot operator and scope resolution operator?

whats the differnce between dot operator and scope resolution operator in c++

2 Answers

  • 1 decade ago
    Favorite Answer

    The dot operator is used to refer to a specific member of a class when you have a reference to the class in question. For example:

    MyCoolClass foo;

    foo.bar = 1;

    foo.process( bigData );

    On the other hand, if you have a pointer to a class (which is common), you'd use the arrow syntax:

    MyCoolClass* foo = new MyCoolClass();

    foo->bar = 1;

    foo->process( bigData );

    But the scope resolution operator specifies scope, that is, at what level something exists. It's used to define methods and to specify where something resides if it isn't in the immediate scope. For example:

    void MyCoolClass::process( int someData ) // a method (or function) definition


    // this class has a function called printf()

    printf( "Hello World" ); // calling this class's printf()

    ::printf( "Hello World" ); // calling the global printf()


    It can also be used to call static member functions:


    int myProduct = MyCoolClass::MultiplyTwo( 5, 7 );


    I know it can be confusing, but you'll get the hang of it. Check out the link below for more information. HTH

  • 5 years ago

    The main use for this operator will be useful in c++programmig. If you have a class called A and class called B and in both the classes if you have the same function with the name read() and you want to define the function out side the class witout using scope resolution operator then its not possible cos compiler will be confusion which function to cal! so we can use lik void A::read() for A's read void B::read() for B.s read. in short i can tell you lik this operator tells the scope of members.

Still have questions? Get your answers by asking now.