person.h

来自「Wrox.Ivor.Hortons.Beginning.Visual.C.Plu」· C头文件 代码 · 共 57 行

H
57
字号
// Person.h
// A class defining a person
#pragma once
#include <iostream>
#include <string>
#include <functional>
using std::cout;
using std::endl;
using std::string;

class Person
{
public:
  Person(string first = "", string second = "")
  {
    firstname = first;
    secondname = second;
  }
/*
  // Copy constructor
  Person(const Person& p)
  {
    firstname = p.firstname;
    secondname = p.secondname;
  }
  // Assignment operator
  Person& operator=(const Person& p)
  {
    if(this == &p)
      return *this;
    firstname = p.firstname;
    secondname = p.secondname;
    return *this;
  }
*/
  // Less-than operator
  bool operator<(const Person& p)const
  {
    if(secondname < p.secondname ||
      ((secondname == p.secondname) && (firstname < p.firstname)))
      return true;

    return false;
  }


  // Get the name 
  string getName()const
  {
    return firstname + " " + secondname;
  }

private:
  string firstname;
  string secondname;
};

⌨️ 快捷键说明

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