[英]struct not recognized in eclipse cdt
I am trying to write a console-based calculator by eclipse cdt.But there seems to be a problem with recognize my struct Calc 我正在尝试通过eclipse cdt编写基于控制台的计算器。但是识别我的结构Calc似乎存在问题
There is my header file: 有我的头文件:
#ifndef __CALC_H__
#define __CALC_H__
#include <iostream>
struct Calc {
Calc();
Calc(const Calc &other);
bool error;
int display;
char oper;
int result;
int memory;
void digit(int digit);
void op(char oper);
void equals();
void memPlus();
void memClear();
void memRecall();
bool isError() const;
void allClear();
};
std::ostream &operator<<(std::ostream &out, const Calc &c);
#endif
and my source file 和我的源文件
#include "calc.h"
void doOperation(Calc& calc){
switch(calc.oper){//ide tells me oper cant be resolved
case '+':
break;
case '-':
break;
case '*':
break;
case '/':
break;
}
}
void Calc(){
}
void Calc(const Calc& other){//ide tells me Calc does not name a type
}
So the problems are 1.oper cannot be recognized as a data member of Calc 2.when I use Calc as parameter, eclipse cant find the type Calc Where did I do wrong? 所以问题是1.oper无法识别为Calc的数据成员2.当我使用Calc作为参数时,eclipse无法找到Calc类型我在哪里做错了? Thanks in advance!
提前致谢!
2 things, first constructors do not have a return type so 2件事,第一个构造函数没有返回类型,所以
void Calc() {}
is not the way to go - lose the void
return type. 不是要走的路-失去
void
返回类型。 Second you need to use the scope resolution operator on your Calc
member functions - again lose the void
其次,您需要使用范围解析操作上的
Calc
成员函数-再次失去void
Calc::Calc(const Calc& other){
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.