xxxxxxxxxx
int main() {
House red_house; // Calls House() default constructor
red_house.summary();
return 0;
}
xxxxxxxxxx
class House {
private:
std::string location;
int rooms;
public:
// Default constructor
House() {
location = "New York";
rooms = 5;
}
void summary() {
std::cout << location << " house with " << rooms << " rooms.\n";
}
};
xxxxxxxxxx
class House {
private:
std::string location;
int rooms;
public:
// Constructor with default parameters
House(std::string loc = "New York", int num = 5) {
location = loc;
rooms = num;
}
void summary() {
std::cout << location << " house with " << rooms << " rooms.\n";
}
};
xxxxxxxxxx
int main() {
House default_house; // Calls House("New York", 5), default
House texas_house("Texas"); // Calls House("Texas", 5)
House big_florida_house("Florida", 10); // Calls House("Florida", 10)
}
xxxxxxxxxx
House big_house(10); // Error: no constructor to handle House(int)