0

我正在尝试通过 eclipse cdt 编写一个基于控制台的计算器。但是识别我的 struct Calc 似乎有问题

有我的头文件:

#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

和我的源文件

#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

}

所以问题是 1.oper 不能被识别为 Calc 的数据成员 2.当我使用 Calc 作为参数时,eclipse 找不到类型 Calc 我哪里做错了?提前致谢!

4

1 回答 1

0

两件事,第一个构造函数没有返回类型,所以

void Calc() {}

不是要走的路 - 失去void返回类型。其次,您需要在Calc成员函数上使用范围解析运算符 - 再次丢失void

 Calc::Calc(const Calc& other){
 }
于 2012-10-30T23:56:28.600 回答