static member methods

Here is an example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream>
using namespace std;

class tmp2
{
public:
	void test()
	{
		cout<<"we are now in the function 'test'"<<endl;
		return;
	}
};


class tmp
{
public:
	static int hoofd()
	{
		cout<<"this is in 'hoofd'"<<endl;
		tmp2 k;
		k.test();
		cout<<"this was the einde"<<endl;
		return 0;
	}
};

int main()
{
	tmp::hoofd();
	return 0;
}


Look at the main-function. i've declared a member method to be static. bu why do i have to write tmp::hoofd, and not tmp.hoofd??
please answer quick
. is used to access data in a specific object (e.g. object.member) and to pass objects as the this parameter to functions (e.g. object.function()).
:: is used for scope resolution.

There is no technical reason for not doing it like you say, but this way is just more coherent.
Last edited on
Topic archived. No new replies allowed.