Calling Member Functions within Main C++


Question

#include <iostream>

using namespace std;

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

void MyClass::printInformation()
{
     return;
}

int main()
{

    MyClass::printInformation();

    fgetc( stdin );
    return(0);
}

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

1
9
7/28/2012 7:40:35 PM

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

MyClass m;

m.printInformation();
30
3/25/2009 5:53:53 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon