simpcopy.cpp

来自「Think in C++ 2nd」· C++ 代码 · 共 39 行

CPP
39
字号
//: C12:Simpcopy.cpp

// From Thinking in C++, 2nd Edition

// Available at http://www.BruceEckel.com

// (c) Bruce Eckel 1999

// Copyright notice in Copyright.txt

// Simple operator=()

#include <iostream>

using namespace std;



class Value {

  int a, b;

  float c;

public:

  Value(int aa = 0, int bb = 0, float cc = 0.0) {

    a = aa;

    b = bb;

    c = cc;

  }

  Value& operator=(const Value& rv) {

    a = rv.a;

    b = rv.b;

    c = rv.c;

    return *this;

  }

  friend ostream&

    operator<<(ostream& os, const Value& rv) {

      return os << "a = " << rv.a << ", b = "

        << rv.b << ", c = " << rv.c;

    }

};



int main() {

  Value A, B(1, 2, 3.3);

  cout << "A: " << A << endl;

  cout << "B: " << B << endl;

  A = B;

  cout << "A after assignment: " << A << endl;

} ///:~

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?