C++ Create Object Array without default constructor -
i error when dynamically creating array of (transaction) object. error output says:"no matching function call 'transaction::transaction()' part of assignment , not allowed use default constructor. gather array automatically assigns values each of indexed address when it's created , no default constructor made transaction, cannot without values. please me see fix error.
class transaction { private: int id; float amount; string fromaddress, toaddress, signature; bool confirmed, removefrompool; static int numtransactions; public: transaction(string in_fa, string in_ta,string in_sign,float in_amount); transaction(transaction &obj); int getid() const; } //--------------------- class block { private: int id, txcount; const int max_tx=5; transaction** txlist; string blockhash, prevblockhash, minername; bool confirmed; public: block(int id,string prevh,string name); } //------------------ // block.cpp block::block(int i, string prevh, string name) { *txlist = new transaction[max_tx]; }
if insist on using plain dynamic array, could this:
*txlist = new transaction[max_tx]{{"1", "2", "3", 4}, // 3 more {"5", "6", "7", 8}};
but instead declare constructor as:
transaction(string in_fa = "a", string in_ta = "b", string in_sign = "c", float in_amount = 42);
and attempt dodge silly 'no default ctor' requirement.
Comments
Post a Comment