https://rentry.org/PPP2_p265b

// Code derived from Stroustrup's PPP2 book
// § 8.3 Header files
//  -and beginning on p 265

//------------------------------------------------------------------------------
// as filename: token.h

class Token {};

class Token_stream {
 public:
  Token putback(Token t);

 private:
  // bool  full;
  Token buffer;
};

//------------------------------------------------------------------------------
// as filename: token.cpp

// #include "token.h"  // <--- #include'd here (in definition file)

Token Token_stream::putback(Token t)
{
  buffer.push_back(t);  // error
  return t;
}

//------------------------------------------------------------------------------
// as filename: main.cpp

// #include "token.h"  // <--- also #include'd here (in usage file)

Token_stream ts;

int main()
{
  Token t = ts.gett();  // error: no member gett

  // . . .

  ts.putback();  // error: argument missing
}

build & run:

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

PrevUpNext

Edit
Pub: 04 Apr 2023 14:25 UTC
Edit: 02 May 2023 22:28 UTC
Views: 621