-1

I found this line of code where I'm working, but I don't quite understand its meaning:

virtual method1::method2::method3 f() = 0;

In the main function, I have method1::method2::method3.g1().g2(). I really don't understand. I know method::A where A is a class.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • 1
    You probably should use a good book for learning c++. Those are namespaces and not methods. – t.niese Feb 12 '22 at 16:20
  • `::` is a scope resolution operator that checks the right hand operand in the scope of left hand operand. – Abhilekh Gautam Feb 12 '22 at 16:23
  • 1
    If `X::Y::Z` is valid, either `X` is a namespace, or `Y` is a *member class* or *member type* alias of class `X`. – aschepler Feb 12 '22 at 16:36
  • 1
    Impossible to say without seeing how `method1`, `method2`, and `method3` are defined. Despite the names given here, they are definitely not member functions (sometimes inaccurately referred to as "methods"). – Pete Becker Feb 12 '22 at 18:07

2 Answers2

1

:: is a scope operator.

You may need to append multiple of them either when using nested classes (a class defined within another class) or when you use namespaces. Resolution is done the same way.

Obsidian
  • 3,719
  • 8
  • 17
  • 30
  • 1
    A third possibility: `class X { public: static int n; }; class Y { public: using Z = X; };` and then `Y::Z::n` is a valid name. – aschepler Feb 12 '22 at 16:39
0

:: is the scope resolution operator. It allows you to statically traverse scopes such as namespaces and classes in order to reference the identifier you want.

I think what you have is not methods but namespaces and classes.

georgep
  • 731
  • 1
  • 12