I have the following class:
The bold line gives me the following error:Code:class Stuff { private: int val; public: Stuff (int Val) { this.val = Val; } int GetVal() { return this.val; } void SetVal(int Val) { this.val = Val; } };
error C2228: left of '.val' must have class/struct/union
If I change it to
I get the following error:Code:Stuff.val = Val;
error C2143: syntax error : missing ';' before '.'
What would be the correct way of creating a constructor that takes an int and assigns this int to val?
In general, what would be the correct way to address a variable of the class?
In C# I'd use this to refer to the current object, but I can't seem get that to work in C++.
Also, when I create a new Stuff object, what would be the correct syntax?
Wouldcreate a new, uninitialized object of the Stuff class with static memoryCode:A = Stuff;
and woulddynamically allocate a new object the Stuff class, with an initialized value of 2, which is assigned to the variable val?Code:A = new Stuff(2);
Thanks in advance.