2012-10-30 102 views
0

我想寫的日食基於控制檯的計算器cdt.But那裏似乎是承認我的結構Calc的問題結構不是在Eclipse CDT的認可

有我的頭文件:

#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不能被識別爲計算器 2,當數據的成員,我用計算器如對米,日食找不到類型Calc 我在哪裏做錯了? 在此先感謝!

+0

雖然這可能會變得更加複雜,我不知道,你真正需要的構造的這個例子。您可能對本教程感興趣http://www.cplusplus.com/doc/tutorial/structures/,其中涵蓋了結構的基礎知識。 –

回答

0

兩件事情,第一個構造函數沒有返回類型,以便

void Calc() {} 

是不是要走的路 - 失去了void返回類型。其次,您需要使用範圍解析操作上的Calc成員函數 - 再次失去了void

Calc::Calc(const Calc& other){ 
}