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
is not the way to go – lose the
voidreturn type. Second you need to use the scope resolution operator on yourCalcmember functions – again lose thevoid