[try Beta version]
Not logged in

 
 
member variables vs member functions

Apr 26, 2015 at 9:46am
I seriously do not know what the difference is, could anybody please provide a sample as to what a member variable is and what a member function is?

Thank you so much in advance!
Apr 26, 2015 at 9:58am
A member function is a function that is part of a class.

A member variable is a variable (an object) that is part of a class.

1
2
3
4
5
6
7
class Class
{
public:
	void memberFunction();
private:
	int memberVariable;
};
Last edited on Apr 26, 2015 at 10:01am
Apr 26, 2015 at 10:02am
Thank you so much for responding Peter!

So, just to clarify, according to the definition then, something like (below) would be following my teacher's guidelines ? (she said we can only have three member variables)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class Date
{
private:
int day,month,year ;

public:



Date operator//
Date operator//

friend ostream &operator//
friend istream &operator//
Date() //
Date//
void blabla//
int getDate() //
bool operator //
bool operator //
};

Last edited on Apr 26, 2015 at 10:03am
Apr 26, 2015 at 10:04am
Yes, your Date class has three member variables day, month and year.
Apr 26, 2015 at 10:06am
Thank you very much for the help, you cleared up my confusion over this definition (and now I can turn in this project finally..)

I hope you have a nice day / night !!
Topic archived. No new replies allowed.