modules/person1.cppm

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. Creative Commons License

// raw code

module;
#include <iostream>
#include <string>

export module ModPerson;   // THE module interface

class Person {             // note: \IBnot exported
   std::string name;
public:
   Person(std::string n)
    : name{std::move(n)} {
   }
   std::string getName() const {
     return name;
   }
};

std::ostream& operator<< (std::ostream& strm, const Person& p)
{
  return strm << p.getName();
}

export Person getPerson(std::string s) {
  return Person{s};
}