Calling Member Functions within Main C++

前端 未结 7 1503
野的像风
野的像风 2021-02-04 12:24
#include 

using namespace std;

class MyClass
{
public:
       void printInformation();
};

void MyClass::printInformation()
{
     return;
}

int main(         


        
7条回答
  •  隐瞒了意图╮
    2021-02-04 12:43

    On an informal note, you can also call non-static member functions on temporaries:

    MyClass().printInformation();
    

    (on another informal note, the end of the lifetime of the temporary variable (variable is important, because you can also call non-const member functions) comes at the end of the full expression (";"))

提交回复
热议问题