• 0

A Simple C++ Question


Question

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

  • 0

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

  • 0
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

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.