Header files and several sources
Declarations in a .hpp / .h file, definitions in a .cpp file; the IDE links them into your program.
Runs in Zerethon IDE · C++ (GCC 14)
Official C++ documentation ↗
main.cpp
#include <iostream>
#include "geometry.hpp"
int main() {
std::cout << geometry::area(3, 4) << '\n';
}
geometry.hpp
#pragma once
namespace geometry {
int area(int width, int height);
}
geometry.cpp
#include "geometry.hpp"
namespace geometry {
int area(int width, int height) { return width * height; }
}
Output
12
- Run compiles the entry together with every other
.cpp/.ccfile whose name does not start withmainortest_. #pragma once(or an include guard) stops a header from being included twice.- Only the C++ standard library is available; other libraries (Boost, fmt, …) are not installed.