友元类的作用
如果把A类作为B类的友元类,
那么A类的所有成员函数【在A类的成员函数内】,就可以直接访问【使用】B类的私有成员。
即,友元类可以直接访问对应类的所有成员!!!
Computer.h
#pragma once
#include <string>
using namespace std;
class Server; //声明类
class Computer{
public:
Computer();
string description() const;
//把Server声明成友元类
friend class Server;
protected:
string cpu; //计算机的CPU芯片
};
Computer.cpp
#include <