错误:表达式必须具有类类型 [英] error: expression must have a class type
本文介绍了错误:表达式必须具有类类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我得到一个错误:表达式必须具有类类型
首先,我不明白为什么会出现此错误。我创建并反对并使用它。
在我的main中:
I get the error: expression must have a class type Firstly, I don't understand why I am getting this error. I create and object and use it. in my main:
#include "Worker.h"
int main()
{
Worker myWorker();
myWorker.inputInfo();
myWorker.displayPayBarGraph();
}
Worker.h
//Worker.h
//Definition of class Workers
//Member functions are defined in Worker.cpp
//Worker class defintion
class Worker
{
public:
Worker(); //constructor initializes worker type
void inputInfo(); //attains worker information
void displayPayBarGraph(); //prints a bar graph representation of the pay
private:
int workerCode; //worker type
//PAY FOR EACH WORKER
double code1pay; //manager
double code2pay; //hourly workers
double code3pay; //commission workrs
double code4pay; //pieceworkers
int hourlyWorkerPay(double, int); //returns the pay of hourly workers
int commissionPay(int); //returns the commission workers pay
int pieceWorkerPay(int, int); //returns the pieceworkers pay
};
推荐答案
此行:
Worker myWorker();
声明一个函数,不带任何参数并返回一个工作者
。
declares a function taking no parameters and returning a Worker
.
只需声明您的对象:
Worker myWorker;
这篇关于错误:表达式必须具有类类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文