OUR FIRST C++ class:
* a class is a way to make a new type! although some are
included with C++
* you learn about *writing* your own classes in CS 112,
but we'll *use* a few classes in CS 111
* string is a C++ class included with C++
* classes have methods
* methods are functions that "belong" to a class
* when you make, say, a parameter or a named
constant be of a type that's a class,
that parameter or constant is an instance
of that class
and that parameter or constant can use that class's methods!
* when a class has a method,
an instance can call it with:
instance.method_name(arg_expr1, arg_expr2, ...)
* say I have,
const string MY_NAME = "Sharon M. Tuttle";
* hey, string has a length method,
it expects no arguments, and returns
the calling string's length!
MY_NAME.length() // call the length method of string
// MY_NAME
MY_NAME.length() == 16
* OHMIGOSH! string class has a + operator!
you can APPEND string instances with
+
MY_NAME + MY_NAME == "Sharon M. TuttleSharon M. Tuttle"
you CANNOT use + with JUST char* literals,
but you CAN if at least one operand IS a string!!
MY_NAME + "!" == "Sharon M. Tuttle!"
* (yes, you can use == to compare a string and a char*,
fortunately! it returns true if they contain
the same characters...)