C ++ class name as a member of a class

What does the postfix expression AttrNode().AttrNodein mainthe following code? Both gcc and clang can compile code without errors. This seems to be legal in C ++ standards. But what is the meaning of such code? Why do C ++ standards allow such use?

#include <stdio.h>

struct AttrNode {
public:
     AttrNode() {}
     static void make() {}
};

int main() {
    AttrNode().AttrNode::make();
    return 0;
}

Thank!

+4
source share
1 answer

AttrNode::has the qualification of a name maketo explicitly call AttrNode::make, and not any other function called make.

In this case, it is redundant; AttrNode().make()will do the same: create a temporary object, call a function, and then destroy the object. Since this is a static function, you usually call it, without creating an object AttrNode::make().

, , , - . , .

+8

All Articles