The following code example is taken from the book
C++20 - The Complete Guide
by Nicolai M. Josuttis,
Leanpub, 2021
The code is licensed under a
Creative Commons Attribution 4.0 International License.
// raw code
module; // start module unit with global module fragment
#include <string>
#include <vector>
export module Mod2; // module declaration
import :Order; // import internal partition Order
export class Customer {
private:
std::string name;
std::vector<Order> orders;
public:
Customer(const std::string& n)
: name{n} {
}
void buy(const std::string& ordername, double price) {
orders.push_back(Order{1, ordername, price});
}
void buy(int num, const std::string& ordername, double price) {
orders.push_back(Order{num, ordername, price});
}
double sumPrice() const;
double averagePrice() const;
};