Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

c++ define constructor with parameters

class House {
private:
  std::string location;
  int rooms;
 
public:
  // Default constructor
  House() {
    location = "New York";
    rooms = 5;
  }
 
  // Constructor with parameters
  House(std::string loc, int num) {
    location = loc;
    rooms = num;
  }
 
  void summary() {
    std::cout << location << " house with " << rooms << " rooms.
";
  }
};
Source by www.codecademy.com #
 
PREVIOUS NEXT
Tagged: #define #constructor #parameters
ADD COMMENT
Topic
Name
3+9 =