I am trying to write a console-based calculator by eclipse cdt.But there seems to be a problem with recognize my struct 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? Thanks in advance!
2 things, first constructors do not have a return type so
void Calc() {}
is not the way to go - lose the void
return type. Second you need to use the scope resolution operator on your Calc
member functions - again lose the void
Calc::Calc(const Calc& other){
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.