Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

c++ destructor

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.
";
  }
 
  // Destructor
  ~House() {
    std::cout << "Moved away from " << location;
  }
};
Source by www.codecademy.com #
 
PREVIOUS NEXT
Tagged: #destructor
ADD COMMENT
Topic
Name
1+3 =