C++: error C2064: term does not evaluate to a function
答案:1 悬赏:70
解决时间 2021-02-18 13:22
- 提问者网友:伴他一生,无悔
- 2021-02-18 01:29
文件一:Teacher.h
#include<iostream>
#include<string>
using namespace std;
class Teacher
{
private:
string name;
int age;
char sex;
string address;
string phone;
string title;
public:
Teacher(string a="abcd",int b=1,char c='W',string d="abcd",string e="abcd",string f="abcd")
{
name=a;
age=b;
sex=c;
address=d;
phone=e;
title=f;
}
void display();
};
文件二:Cadre.h
#include<iostream>
#include<string>
using namespace std;
class Cadre
{
private:
string name;
int age;
char sex;
string address;
string phone;
protected:
string post;
public:
Cadre(string a="abcd",int b=10,char c='W',string d="abcd",string e="abcd",string f="abcd")
{
name=a;
age=b;
sex=c;
address=d;
phone=e;
post=f;
}
};
文件三:Teacher_Cadre.h
#include<iostream>
#include"Teacher.h"
#include<string>
#include"Cadre.h"
using namespace std;
class Teacher_Cadre:public Teacher,public Cadre
{
private:
int wages;
Teacher t1;
Cadre c1;
public:
Teacher_Cadre(string a,int b,char c,string d,string e,string f,string g,int h)
{
t1(a,b,c,d,e,f); // error C2064: term does not evaluate to a function
c1(a,b,c,d,e,g); // error C2064: term does not evaluate to a function
wages=h;
}
void show()
{
display();
cout<<"post:"<<post<<endl;
}
}
文件四:display.cpp
#include<iostream>
#include"Teacher.h"
#include<string>
using namespace std;
void Teacher::diplay()
{
cout<<"name:"<<name<<endl;
cout<<"age:"<<age<<endl;
cout<<"sex:"<<sex<<endl;
cout<<"address:"<<address<<endl;
cout<<"phone:"<<phone<<endl;
cout<<"title:"<<title<<endl;
}
文件五:main.cpp
#include<iostream.h>
#include"Teacher_Cadre.h"
using namespace std;
int main()
{
Teacher_Cadre x1("xiaoli",20,'M',"sichuan","123456789","wu","student",0);
x1.show();
return 0;
}
最佳答案
- 二级知识专家网友:兮沫♡晨曦
- 2021-02-18 02:04
构造函数不是这样构造的,你都还没创建对象,怎么能用 t1(a,b,c,d,e,f);呢?
改成如下的就OK了:
Teacher_Cadre(string a,int b,char c,string d,string e,string f,string g,int h)
{
//t1(a,b,c,d,e,f); // error C2064: term does not evaluate to a function
//c1(a,b,c,d,e,g); // error C2064: term does not evaluate to a function
Teacher(a,b,c,d,e,f);
Cadre(a,b,c,d,e,f);
wages=h;
}
自己再好好想想,参考下书~
改成如下的就OK了:
Teacher_Cadre(string a,int b,char c,string d,string e,string f,string g,int h)
{
//t1(a,b,c,d,e,f); // error C2064: term does not evaluate to a function
//c1(a,b,c,d,e,g); // error C2064: term does not evaluate to a function
Teacher(a,b,c,d,e,f);
Cadre(a,b,c,d,e,f);
wages=h;
}
自己再好好想想,参考下书~
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯