Skip to content

Instantly share code, notes, and snippets.

@GavinRay97
Created January 21, 2023 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GavinRay97/d17e5b2cc1647f1713120d8502b841c3 to your computer and use it in GitHub Desktop.
Save GavinRay97/d17e5b2cc1647f1713120d8502b841c3 to your computer and use it in GitHub Desktop.
C++ Modules Example
// Compile with:
// $ /opt/gcc-latest/bin/g++ --std=c++2b -fmodules-ts other-module.cxx example-module.cxx -o example
// Global module fragment where #includes can happen
module;
#include <iostream>
// first thing after the Global module fragment must be a module command
export module example;
import other_module;
int main()
{
OtherClass other;
other.say_bar();
std::cout << "Hello, world! " << std::endl;
}
// Global module fragment where #includes can happen
module;
#include <iostream>
// first thing after the Global module fragment must be a module command
export module other_module;
export class OtherClass
{
public:
void say_bar()
{
std::cout << "bar" << std::endl;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment