Class declaration

I'm studying class and I dont understand why the scope resolution operator is needed in this code. float v was declared inside the class so then why is A::v needed

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
  
class A {
public:
	float v;
	float set(float v) {
		A::v += 1.0;// line not understand
		return v;
	}
	float set(void) {
		A::v = v + 1.0;//here as well
		return 0.0;
	}
	float get(float v) {
		v += A::v;//here a swell
		return v;
	}
};
Put the code you need help with here.
I'm thinking that it is not necessary
1
2
3
4
	float set(float v) {
		A::v += 1.0;// line not understand
		return v;
	}

You have v as a parameter so doing this
v += 1.0;// line not understand
will alter the parameter v and not the member variable v.

1
2
3
4
	float set(void) {
		A::v = v + 1.0;//here as well
		return 0.0;
	}

You don't need to explicitly specify the scope here.
v = v + 1.0;//here as well
will work just fine.

1
2
3
4
	float get(float v) {
		v += A::v;//here a swell
		return v;
	}

Same logic as set().
Last edited on
Topic archived. No new replies allowed.