This repo contains some code demonstrating the basics of C++ classes. You can find class declarations in the .hpp
files and class implementations in the corresponding .cpp
files.
There are a few different examples here, each in a different set of files:
-
point.hpp
andpoint.cpp
contain the interface and implementation of a basic class representing a point in 2D space. This class demonstrates some of the most basic essentials of C++ classes, including the syntax for declaring and implementing a class and its methods, the different types of class constructors, accessors, and mutators, etc. There is an application inpoint-stuff.cpp
that demonstrates basic class usage using thisPoint
class. -
student.hpp
andstudent.cpp
contain the interface and implementation of a class representing a student. This class demonstrates some of more advanced class essentials, especially ones related to classes that use dynamically allocated members. When you have a class like this, you typically need to implement a copy constructor, an assignment operator, and a destructor, as we do for theStudent
class. There is an application instudent-stuff.cpp
that demonstrates the usage of this class.
You can compile this code using the provided makefile and then run it as follows:
make
./point_stuff
./student_stuff
You can also run the command make clean
to clean up the directory of files generated by compilation.