• Write some C++ Code
  • Write some C++ Code

    Create Directories

    First we create a simple C++ project.

    1. Create a folder as project root directory
      mkdir example-project
      cd example-project
    2. Create two subfolders, one for the source, one for the headers:
      mkdir include
      mkdir src

    You can also use different directory structure. You just have to be consistent.

    Create Header File

    Create a C++ Headerfile include/my-class.h

    namespace MyNamespace
    {
      class MyClass
      {
      public:
        int myVar;
    
        int myFunction() const;
      };
    }

    Create Source File

    Create a C++ Sourcefile include/my-class.cpp

    #include <my-class.h>
    
    namespace MyNamespace
    {
      int MyClass::myFunction(int x) const
      {
        char letter = '4' + std::string("2");
    
        return myVar - x + 42;
      }
    }