在此范围内未声明"变量"

Aye*_*Jay 0 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
Run Code Online (Sandbox Code Playgroud)

这是我的头文件

    #ifndef TRANSACTION_H
    #define TRANSACTION_H

    #include <string>
    using namespace std;

    #include "defs.h"

    class Transaction
    {
      public:
        Transaction(TransType = TTERROR, TransState = TSERROR,int = 0 ,float = 0);
        int         getTransID();
        TransType   getTType();
        TransState  getTState();
        string      getDate();
        int         getTAcctNum();
        void        setDate(string);
        float       getAmount();
      private:
        static int  nextTransID;
        int         transID;
        TransType   tType;
        TransState  tState;
        string      date;
        int         tAcctNum;
        float       tAmount;


    };

    #endif
Run Code Online (Sandbox Code Playgroud)

这是我的源文件

#include "Transaction.h"
#include "defs.h"

#include <string>
using namespace std;

int Transaction::nextTransID = 2001;

Transaction::Transaction(TransType t, TransState s, int acct, float amount)
{
  transID   = nextTransID++;
  tType     = t;
  tState    = s;
  tAcctNum  = acct;
  tAmount   = amount;
}

int getTransID()        { return transID;  }
TransType getTType()    { return tType;    }
TransState getTState()  { return tState;   }
string getDate()        { return date;     }
int getTAcctNum()       { return tAcctNum; }
float getTAmount()      { return tAmount;  }


void setDate(string d)
{
  date = d;
}
Run Code Online (Sandbox Code Playgroud)

我有点迷失在什么问题上

unw*_*ind 7

这个:

int getTransID()        { return transID;  }
Run Code Online (Sandbox Code Playgroud)

与你的班级无关,它是一个全球性的功能.

你的意思是:

int Transaction::getTransID() { return transID;  }
Run Code Online (Sandbox Code Playgroud)

此外,应该使该函数(和其他getter)const表示它们不修改对象.