Calling Member Functions within Main C++

前端 未结 7 1510
野的像风
野的像风 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:52

    If you want to make your code work as above, the function printInformation() needs to be declared and implemented as a static function.

    If, on the other hand, it is supposed to print information about a specific object, you need to create the object first.

提交回复
热议问题