https://rentry.org/PPP2_p305

// Code derived from Stroustrup's PPP2 book
// § 9.2 Classes and members
//  -and beginning on p 305

class X {
 public:
  int mf(int v)  // class function member
  {
    int old = m;
    m       = v;

    return old;
  }

  int m;  // class data member
};

int main()
{
  X var;              // var is a local (automatic) variable of type X
  var.m = 7;          // assign to var's data member m
  int x = var.mf(9);  // call var's member function mf()

  return x;
}

build & run:

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

UpNext

Edit
Pub: 05 Apr 2023 15:26 UTC
Edit: 03 May 2023 00:57 UTC
Views: 499