在Main C ++中调用成员函数 [英] Calling Member Functions within Main C++

查看:74
本文介绍了在Main C ++中调用成员函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include <iostream>

using namespace std;

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

void MyClass::printInformation()
{
     return;
}

int main()
{

    MyClass::printInformation();

    fgetc( stdin );
    return(0);
}

如何在 main 中调用 printInformation 函数?该错误告诉我,我需要使用一个类对象.

How would I call the printInformation function within main? The error tells me that I need to use a class object to do so.

推荐答案

声明MyClass的实例,然后在该实例上调用成员函数:

Declare an instance of MyClass, and then call the member function on that instance:

MyClass m;

m.printInformation();

这篇关于在Main C ++中调用成员函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆