Defining a Member Function

Hello!
I've started to learn object oriented c++ recently, im trying to figure out how to print out a command like cout<< does but with using classes and functions.

I have this example
void DayOfYear::output() { cout << “month = “ << month << “, day = “ << day << endl; }

but when i tried to do something close to it, it didnt work.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>

using namespace std;
class Hello
{
	public:
       void   output();
	private:
	
        string word;
        
};
	void Hello::output()		{		cout << "Hello"<< endl;		} 

void main()
{
	system("pause");
}


i know its a very bad question, but I'm learning.
Last edited on
What do you have proble with?
remember, you need an instance of class to use member functions:
1
2
3
4
5
int main()
{
    Hello hi;
    hi.output();
}
Thanks alot! i knew i had to write something in the main, wasnt sure what is it though!
Topic archived. No new replies allowed.