I.love(You)

今天是春节呢。写一个小程序玩。

#include <iostream>
#include <string>
using namespace std;
class guy
{
    public:
        guy(string nam):name(nam){}
        void love(guy&);              //类的引用作为参数
    private:
        string name;
};
void guy::love(guy& p)
{
    cout<<name<<" loves "<<p.name<<'!'<<endl;
}
int main()
{
    guy I("Walter"),You("Bright");
    I.love(You);                     //“核心”代码
    return 0;
}

 

你可能感兴趣的:(I.love(You))