+ 1

How do I use variables from class in another class?

Example: class Class1{ public: int x = 7; }; class Class2{ public: int addition(int y = 5){ int sum = y + x; return sum; } }; //When I try to run something like this it tells me that x was not declared in this scope.

29th Aug 2019, 6:46 PM
Mythical Coding
Mythical Coding - avatar
1 Odpowiedź
+ 1
In Class2, add: Class1 class1instance; and then call class property under the instance: int sum = y + class1instance.x;
29th Aug 2019, 9:26 PM
Gordon
Gordon - avatar