问题描述
- 求c++大神,友元类,代码如下
- #include
#include
#include
using namespace std;class interviewee
{
public:
friend class interviewer;
interviewee(string ming1int age1string job1)
{
ming=ming1;age=age1;job=job1;
}
interviewee(){}
friend showinfo(interviewee a)
{
cout<<a.ming<<""t""<<a.age<<""t""<<a.job<<endl;
}
private:
string mingjob;
int age;
};class interviewer
{
public:
void getinfo(interviewee v)
{
vi.ming=v.ming;vi.age=v.age;vi.job=v.job;
}
void showinfo()
{
cout<<vi.ming<<"" ""<<vi.age<<"" ""<<vi.job;
}
private:
interviewee vi;
};void main()
{
interviewee iv1(""李依依""20路测工程师"");
showinfo(iv1) ;
interviewer s;
interviewer.getinfo(iv1);
interviewer.showinfo();
}有错误error C2143: syntax error : missing ';' before '.'
怎么改呢?
解决方案
interviewer.getinfo(iv1);interviewer.showinfo();
改为
s.getinfo(iv1);s.showinfo();
解决方案二:
别忘了给楼上兄台结贴哦