Content deleted Content added
|
|
==== Example ====
{{excerpt|Precompiled header|Example}}
A simple example of using C++ modules is as follows:
{{mono|MyClass.cppm}}
<syntaxhighlight lang="cpp">
export module myproject.MyClass;
import std;
using String = std::string;
export namespace myproject {
class MyClass {
private:
int x;
String name;
public:
MyClass(int x, const String& name):
x{x}, name{name} {}
int getX() const noexcept {
return x;
}
void setX(int newX) noexcept {
x = newX;
};
String getName() const noexcept {
return name;
}
void setName(const String& newName) noexcept {
name = newName;
}
};
}
</syntaxhighlight>
{{mono|Main.cpp}}
<syntaxhighlight lang="cpp">
import std;
import myproject.MyClass;
using myproject::MyClass;
int main() {
MyClass me(10, "MyName");
me.setX(15);
std::println("Hello, {}!", me);
}
</syntaxhighlight>
== Attributes ==
|