Created
January 21, 2023 17:43
-
-
Save GavinRay97/d17e5b2cc1647f1713120d8502b841c3 to your computer and use it in GitHub Desktop.
C++ Modules Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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