Matching constructor not found (C++) in HardwareStore Class -
i have been working on hardware store application, there hardwarerecordclass stores info each object in store (ex: nuts, bolts, screws, , forth).
the info stored in ".dat" file, not of import right now.
here's declaration of class:
// definition of hardwarerecord class #ifndef __initialize_hardware_store_file__hardwarerecord__ #define __initialize_hardware_store_file__hardwarerecord__ #include <iostream> class hardwarerecord { public: hardwarerecord(const int& account=0,const std::string& name="",const std::string& description="",const double& price=0.0); //constructor hardwarerecord operator=(hardwarerecord&); //'set' , 'get' functions void setaccountnumber(int); int getaccountnumber() const; void setname(std::string); std::string getname() const; void setprice(double); double getprice() const; void setdescription(std::string); std::string getdescription() const; void wiperecord(); //set blank private: int myaccountnumber; std::string myname; std::string mydescription; double myprice; }; #endif /* defined(__initialize_hardware_store_file__hardwarerecord__) */ here's class definition:
// implementation of hardwarerecord class definition #include <iostream> #include "hardwarerecord.h" using namespace std; hardwarerecord hardwarerecord::operator=(hardwarerecord & arecord) { this->myaccountnumber=arecord.myaccountnumber; this->myname=arecord.myname; this->mydescription=arecord.mydescription; this->myprice=arecord.myprice; homecoming *this; //allow cascaded overloading } hardwarerecord::hardwarerecord(const int& account,const string& name,const string& description,const double& price) { setaccountnumber(account); setname(name); setprice(price); setdescription(description); } void hardwarerecord::wiperecord() { setaccountnumber(0); setname(""); setprice(0); setdescription(""); } void hardwarerecord::setaccountnumber(int num) { if (num < 0) { throw invalid_argument("the business relationship number not in valid range (greater or equal 0)"); } else { myaccountnumber=num; } } int hardwarerecord::getaccountnumber() const { homecoming myaccountnumber; } void hardwarerecord::setname(string name) { myname=name; } string hardwarerecord::getname() const { homecoming myname; } void hardwarerecord::setprice(double price) { if (price < 0) { throw invalid_argument("the cost can not less zero"); } else { myprice=price; } } double hardwarerecord::getprice() const { homecoming myprice; } void hardwarerecord::setdescription(string description) { this->mydescription=description; } string hardwarerecord::getdescription() const { homecoming mydescription; } the class described supposed used in next main.cpp file:
// application models store's record of inventory #include <iostream> #include <fstream> #include <iomanip> #include <cstdlib> #include <sstream> #include "hardwarerecord.h" //hardwarerecord definition using namespace std; //enumeration of choices enum choices {wipe_records,update,list,print,delete,new,end,last}; std::ostream& operator<<(std::ostream& op,const choices& choices) { //print string corresponding value of enum type choices string output=""; switch (choices) { case wipe_records: output = "wipe records"; break; case update: output = "update records"; break; case list: output = "list records"; break; case print: output = "print records"; break; case delete: output = "delete records"; break; case new: output = "add new record"; break; case end: output = "terminate application"; break; case last: output = "an alternative used iterate on values in selection enumeration"; break; default: cerr << "error. invalid value read"; exit(exit_failure); break; } op << output; //print output homecoming op; } //prototype of helper functions int enterchoice(); void wiperecords(fstream&); void updaterecord(fstream&); void listrecords(fstream&); void createtextfile(fstream&); void deleterecord(fstream&); void newrecord(fstream&); int main() { //open file reading , writinbg fstream outrecord ("hardwarerecord.dat",ios::in|ios::out|ios::binary); //exit programme if fstream cannot open file if (!outrecord) { cerr << "file not opened." << endl; exit(exit_failure); } int choice; //user's selection //enable user specify action while ((choice=enterchoice()) !=end) { switch (choice) { case wipe_records: //wipe records clean wiperecords(outrecord); break; case update: //update record updaterecord(outrecord); break; case list: //list current records listrecords(outrecord); break; case print: //print record createtextfile(outrecord); break; case delete: //delete record deleterecord(outrecord); break; case new: //add new record (if space allows) newrecord(outrecord); break; default: //display error if user not select valid selection cerr << "incorrect choice" << endl; } outrecord.clear(); } homecoming 0; } //enable user input menu selection int enterchoice() { //display avaliable options cout << "\nenter choice:\n"<< endl; choices achoice; (int c=wipe_records; c < last; c++) { achoice= (choices) c; cout << c << " - " << achoice << endl; } cout << "\n?: "; int menuchoice; cin >> menuchoice; homecoming menuchoice; } void wiperecords(fstream& thefile) { hardwarerecord temp; (int i=0; < 100;i++) { //convert record binary , assign temp //make temp "wipe itself" } } yes, realize many of functions defined prototype, not declared. done later after problem described shortly afterwards fixed. please direct attending next piece of code, file:
void wiperecords(fstream& thefile) { hardwarerecord temp; //here's error occurs: no matching constructor! (int i=0; < 100;i++) { //convert record binary , assign temp //make temp "wipe itself" } } whenever seek compile project on mac (i utilize xcode), next error line commented. error "no matching constructor initialization of 'hardwarerecord'". however, provide default values constructor of hardwarerecord object, line
hardwarerecord temp; should initialize without problems.
what going on? how can prepare this?
i think problem. in constructor, utilize std::string&, however, never include <string> in code!
along other errors, compiling g++ gives you:
prog.cpp:46:57: error: ‘string’ not name type
this may invalidate default constructor.
c++ constructor matching
No comments:
Post a Comment