HI folks,
This is my code. How can i pass a outside structure parameter to a class method?
using namespace std;
struct status
{
char name[80];
double balance;
unsigned long account_num;
};
class FileHandler
{
public:
FileHandler(string);
~FileHandler();
int getRecords(struct status *);
int putRecords(struct status *);
private:
string fileName;
fstream fPointer; // ref
};
FileHandler :: FileHandler(string fname)
{
fPointer.open(fname, ios::out | ios::binary);
}
int FileHandler :: getRecords(struct status *acc)
{
strcpy(acc.name, "Heartly");
acc.balance = 1000;
acc.account_num = 3;
return 0;
}
int FileHandler :: putRecords(struct status *acc)
{
cout << acc.name << endl;
cout << "Account # " << acc.account_num;
cout.precision(2);
cout.setf(ios::fixed);
cout << endl << "Balance: $" << acc.balance<<endl;
return 0;
}
In FileHandler constructor i got the below error
clshandle.cpp: In constructor ‘FileHandler::FileHandler(std::string)’:
clshandle.cpp:31:45: error: no matching function for call to ‘std::basic_fstream<char>:: open(std::string&, std::_Ios_Openmode)’
/usr/include/c++/4.5/fstream:866:7: note: candidate is: void std::basic_fstream<_CharT, _Traits>:: open(const char*, std::ios_base:: openmode) [with _CharT = char, _Traits = std::char_traits<char>, std::ios_base:: openmode = std::_Ios_Openmode]
in getReords() methods, i got the below error.
clshandle.cpp: In member function ‘int FileHandler::getRecords(status*)’:
clshandle.cpp:53:13: error: request for member ‘name’ in ‘acc’, which is of non-class type ‘status*’
clshandle.cpp:54:6: error: request for member ‘balance’ in ‘acc’, which is of non-class type ‘status*’
clshandle.cpp:55:6: error: request for member ‘account_num’ in ‘acc’, which is of non-class type ‘status*’
clshandle.cpp: In member function ‘int FileHandler:: putRecords(status*)’:
clshandle.cpp:60:14: error: request for member ‘name’ in ‘acc’, which is of non-class type ‘status*’
clshandle.cpp:61:30: error: request for member ‘account_num’ in ‘acc’, which is of non-class type ‘status*’
clshandle.cpp:64:38: error: request for member ‘balance’ in ‘acc’, which is of non-class type ‘status*’