Hello!
I'm relatively new to C++ and I'm learning about classes and objects. I've learned most of what I know from YouTube tutorials and some books. Well, in almost all of those, they mentioned that it was poor programming practice to make all your data members public, inside of a class. If they are all private, how may I access it from different functions? I think I have a general idea of how to go about doing this, and I will post below. Please correct me if I am wrong.
#include <iostream>
class testClass {
private:
int i;
public:
int testFunct(int i){
int i=42;
cout<<i<<endl;
}
};
int main() {
testClass testObj
testObj.testFunct;
}
Basically, what I think the concept is, is to make all your variable definitions in the private section of the class, and then give them values and use them in the public section? The you can pull it straight from the public when you need to use it?
Thanks for any help, and also there may be some errors in the code above :P
Carpetfizz