This is an old revision of the document!
====== C++ Basics ====== C++ is an object-oriented language. You can define new data types and their operations and then program with them much as you program with fundamental types such as %%int, char, float,%% etc. For example, you can define %%Matrix%% and %%Vector%% types and then write high-level linear algebra programs, like Matlab scripts. For example, <code c++> int M = 13; int N = 11; Matrix A(M,N); // Construct a matrix A Vector x(N); // Construct a vector x // ...fill in values of A and x... Vector y = A*x; // Multiply A*x and then set y = A*x // Print the results cout << "y's dimension is " << y.dim() << endl; cout << "y's value is " << y << endl; </code> In C++ * a user-defined type is called a **class**. E.g. %%Matrix%% is a class. Classes are roughly like fundamental types. * variables of user-defined types are often called **objects**. E.g. %%A%% is an object of type %%Matrix%%. * objects are initialized or **constructed** by **constructors** E.g. %%Matrix A(M,N)%% constructs an object named %%x%%. The %%(M,N)%% is an argument list for the %%Matrix%% constructor, in this case the row and columns dimensions. Constructors typically allocate memory and assign initial values to the object's internal data structures. * Classes have **member functions** and **operators**. E.g. %%A*x%% calls the %%Matrix, Vector%% multiplication operation, and %%y.dim()%% calls the %%dim()%% member function of object %%y%%.