https://rentry.org/PPP2_p306

// Code derived from Stroustrup's PPP2 book
// § 9.3 Interface and implementation
//  -and beginning on p 306

class X {  // this class’s name is X
 public:
  // public members:
  // – the interface to users (accessible by all)
  // functions
  // types
  // data (often best kept private)
 private:
  // private members:
  // – the implementation details (used by members of this class only)
  // functions
  // types
  // data
};

int main()
{
  // this C++ attribute prevents an 'unused variable' error by compiler
  [[maybe_unused]]
  // this local instantiation of X uses it's implicit default constructor.
  X x{};
}

build & run:

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

PrevUpNext

Edit
Pub: 06 Apr 2023 14:18 UTC
Edit: 03 May 2023 00:58 UTC
Views: 285