mzkhadir Posted October 12, 2004 Share Posted October 12, 2004 int accountNo; string Lname; string Fname; float balance; what the best way of putting the above in a no arg constructor. This is what I have until now. account(): accountNo(0), balance(0.0) Is there anything else I need to do. Thank You mzkhadir Link to comment Share on other sites More sharing options...
0 kjordan2001 Posted October 12, 2004 Share Posted October 12, 2004 account(): accountNo(0), balance(0.0) should be YourClass::account() { accountNo = 0; balance = 0.0; //and even, if you wanted: string Lname = ""; string Fname = ""; } Link to comment Share on other sites More sharing options...
0 ilmcuts Posted October 12, 2004 Share Posted October 12, 2004 account(): accountNo(0), balance(0.0)should be YourClass::account() { accountNo = 0; balance = 0.0; //and even, if you wanted: string Lname = ""; string Fname = ""; } 584720975[/snapback] Usually it's the other way around. It's too late here for me to write a full reply, but see this in the C++ FAQ Lite. mzkhadir, about your question, if you want Lname and Fname to be empty just omit them as you have done in the code sample you posted. They will then be default-constructed - and in case of std::string that means an empty string. Link to comment Share on other sites More sharing options...
0 mzkhadir Posted October 13, 2004 Author Share Posted October 13, 2004 thank you very much. Link to comment Share on other sites More sharing options...
Question
mzkhadir
int accountNo;
string Lname;
string Fname;
float balance;
what the best way of putting the above in a no arg constructor. This is what I have until now.
account(): accountNo(0), balance(0.0)
Is there anything else I need to do.
Thank You
mzkhadir
Link to comment
Share on other sites
3 answers to this question
Recommended Posts