classes Flashcards
(19 cards)
what is a class
a way to group related data together in an easy to access method
what is an instance of a class
an object
encapsulation
group related data together in an easy to access method
abstraction
when we separate the interface (what the user can do) from the implementation (what actually happens “behind the scenes”)
what is a public member
something declared in a class that can be used outside of a class
what is a private member
functions that are only used inside of the class; must be accessed by members of the class (like setters and getters, which are always public for this reason)
what functions return the number of characters in a string
.length(), .size()
what function checks if the length of the string is 0
.empty()
what function clears the contents of the string
.empty()
what function adds a string/character to the end of a string
.append()
can a member function definition access private data members?
yes!
::
Scope resolution operator
Use when defining a member function of a class (like in cpp files)
Helps private class data become visible
by default, class members are…
private
how do you call a default constructor?
MyClass obj;
*no parenthesis!
what are constructors
- has the same name as the class
- usually starts with a capital letter
- has no return type
what is special about the parameters of setters?
it should not be named the same thing as your member variable
ex: want parameter to be row_in if the variable is row, so that you have no confusion with trying to set row = row
what should you include in a cpp file to reference a class
include “ClassName.h”
what goes in source (cpp) files?
function implementations
*don’t forget scope resolution operator (::) to associate the function with the class!
what goes in the header (.h) file?
where class definition and function declarations go