c++ - "Variable" was not declared in this scope -


i getting error when try compile class. have made sure there function prototypes , variables initilized correctly, can me figure out problem

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’ not declared in scope  int gettransid()        { return transid;  }                                   ^ transaction.cc: in function ‘transtype getttype()’: transaction.cc:19:34: error: ‘ttype’ not declared in scope  transtype getttype()    { return ttype;    }                                   ^ transaction.cc: in function ‘transstate gettstate()’: transaction.cc:20:34: error: ‘tstate’ not declared in scope  transstate gettstate()  { return tstate;   }                                   ^ transaction.cc: in function ‘std::__cxx11::string getdate()’: transaction.cc:21:34: error: ‘date’ not declared in scope  string getdate()        { return date;     }                                   ^ transaction.cc: in function ‘int gettacctnum()’: transaction.cc:22:34: error: ‘tacctnum’ not declared in scope  int gettacctnum()       { return tacctnum; }                                   ^ transaction.cc: in function ‘float gettamount()’: transaction.cc:23:34: error: ‘tamount’ not declared in scope  float gettamount()      { return tamount;  }                                   ^ transaction.cc: in function ‘void setdate(std::__cxx11::string)’: transaction.cc:28:3: error: ‘date’ not declared in scope    date = d;    ^ makefile:31: recipe target 'transaction.o' failed make: *** [transaction.o] error 1 

here header file

    #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 

here source file

#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; } 

i kinda lost on issue

this:

int gettransid()        { return transid;  } 

has nothing class, it's global function.

you meant:

int transaction::gettransid() { return transid;  } 

also, function (and other getters) should made const signal don't modify object.


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -