https://rentry.org/PPP2_p295

// Code derived from Stroustrup's PPP2 book
// § 8.7 Namespaces
//  -and beginning on p 295

// clang-format off
namespace Graph_lib {

struct Color { /* ... */ };
struct Shape { /* ... */ };
struct Line : Shape { /* ... */ };
struct Function : Shape { /* ... */ }; 
struct Text : Shape { /* ... */ };

// ...

int gui_main() { /* ... */ return 0; }

}  // namespace Graph_lib

namespace TextLib {

class Text { /* ... */ };
class Glyph {  /* ... */ };
class Line {  /* ... */ };

// ...

}  // namespace TextLib
// clang-format on

int main() { return Graph_lib::gui_main(); }

build & run:

g++ -std=c++20 -O2 -Wall -pedantic ./ch_08/main_p295.cpp && ./a.out

PrevUpNext

Edit
Pub: 04 Apr 2023 15:19 UTC
Edit: 03 May 2023 00:49 UTC
Views: 571