当我尝试编译我的类时,我收到此错误。我确保有正确的函数原型和变量,希望有人可以帮我找出问题
rdd1:
id1 A
id2 B
id3 C
这是我的头文件
id1 A A
id1 A B
id1 A C
id2 B A
id2 B B
id2 B C
id3 C A
id3 C B
id3 C C
这是我的源文件
g++ -c main.cc
g++ -c BankControl.cc
g++ -c Bank.cc
g++ -c Account.cc
g++ -c View.cc
g++ -c AcctList.cc
g++ -c Customer.cc
g++ -c CustArray.cc
g++ -c Transaction.cc
Transaction.cc: In function ‘int getTransID()’:
Transaction.cc:18:34: error: ‘transID’ was not declared in this scope
int getTransID() { return transID; }
^
Transaction.cc: In function ‘TransType getTType()’:
Transaction.cc:19:34: error: ‘tType’ was not declared in this scope
TransType getTType() { return tType; }
^
Transaction.cc: In function ‘TransState getTState()’:
Transaction.cc:20:34: error: ‘tState’ was not declared in this scope
TransState getTState() { return tState; }
^
Transaction.cc: In function ‘std::__cxx11::string getDate()’:
Transaction.cc:21:34: error: ‘date’ was not declared in this scope
string getDate() { return date; }
^
Transaction.cc: In function ‘int getTAcctNum()’:
Transaction.cc:22:34: error: ‘tAcctNum’ was not declared in this scope
int getTAcctNum() { return tAcctNum; }
^
Transaction.cc: In function ‘float getTAmount()’:
Transaction.cc:23:34: error: ‘tAmount’ was not declared in this scope
float getTAmount() { return tAmount; }
^
Transaction.cc: In function ‘void setDate(std::__cxx11::string)’:
Transaction.cc:28:3: error: ‘date’ was not declared in this scope
date = d;
^
Makefile:31: recipe for target 'Transaction.o' failed
make: *** [Transaction.o] Error 1
我有点迷失在什么问题上
答案 0 :(得分:7)
此:
int getTransID() { return transID; }
与你的班级无关,它是一个全球性的职能。
你的意思是:
int Transaction::getTransID() { return transID; }
此外,该功能(以及其他吸气剂)应该const
表示他们不会修改对象。