x = 42
without first declaring 'x'.my_class.h
. It contains a class definition, but note that the definition is incomplete; the member function do_something
is not defined:#include
directive for 'my_class.h' file in order to have the my_class declaration inserted at this point in the .cpp file, and we include <iostream>
to pull in the declaration for std::cout
. Note that quotes are used for header files in the same directory as the source file, and angle brackets are used for standard library headers. Also, many standard library headers do not have .h or any other file extension.my_class
in another .cpp file. We #include the header file so that the compiler pulls in the declaration. All the compiler needs to know is that my_class is a class that has a public member function called do_something()
.#pragma once
directive to ensure that they are not inserted multiple times into a single .cpp file.