Accessing Class Members
After you define an actual Cat object (for example, Frisky), you use the dot operator (.) to access the member functions of that object. Therefore, to assign 50 to Frisky's itsWeight member variable, you would write
Frisky.itsWeight = 50;
In the same way, to call the Meow() function, you would write
Frisky.Meow();
Assign to Objects, Not to Classes
In C++ you don't assign values to types; you assign values to variables. For example, you would never write
int = 5; // wrong
The compiler would flag this as an error because you can't assign 5 to an integer. Rather, you must define an integer variable and assign 5 to that variable. For example:
int x; // define x to be an int x = 5; // set x's value to 5
This is a shorthand ...
Get Sams Teach Yourself C++ in 24 Hours, Third Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.