Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- int ComputeDistance(const string& source, const string& destination)
- {
- return source.length() - destination.length();
- }
- class Route
- {
- public:
- Route()
- {
- source = "Moscow";
- destination = "Saint Petersburg";
- UpdateLength();
- cout << "Default constructed\n";
- }
- Route(const string& new_source, const string& new_destination)
- {
- source = new_source;
- destination = new_destination;
- UpdateLength();
- cout << "Constructed\n";
- }
- ~Route()
- {
- cout << "Destructed\n";
- }
- string GetSource() const
- {
- return source;
- }
- string GetDestination() const
- {
- return destination;
- }
- int GetLength() const
- {
- return length;
- }
- void SetSource(const string& new_source)
- {
- source = new_source;
- UpdateLength();
- }
- void SetDestination(const string& new_destination)
- {
- destination = new_destination;
- UpdateLength();
- }
- private:
- void UpdateLength()
- {
- length = ComputeDistance(source, destination);
- }
- string source;
- string destination;
- int length;
- };
- void Worthless(Route route)
- {
- cout << 2 << "\n";
- }
- Route GetRoute()
- {
- cout << 1 << "\n";
- return {}; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! возвращаем маршрут, созданный при помощи конструктора по умолчанию
- }
- int main()
- {
- ********************************************************
- cout << 1 << "\n";
- Route route;
- cout << 2 << "\n";
- ********************************************************
- for (int i : {0, 1}) !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- {
- cout << "Step " << i << ": " << 1 << "\n";
- Route route;
- cout << "Step " << i << ": " << 2 << "\n";
- }
- cout << "End\n";
- ********************************************************
- cout << 1 << "\n";
- Route first_route;
- if (false)
- {
- cout << 2 << "\n";
- return 0;
- }
- cout << 3 << "\n";
- Route second_route;
- cout << 4 << "\n";
- ********************************************************
- cout << 1 << "\n";
- Worthless({}); !!!!!!!!!!!!!!!!!!!!!!!!!!!!! маршрут, созданный с помощью конструктора по умолчанию {}
- cout << 3 << "\n";
- ********************************************************
- Route route = GetRoute(); !!!!!!!!!!!!!!!!!!!!!!!!!
- cout << 2 << "\n"; !!!!!!!!!!!!!!!!!!!!!!!!!
- 1
- Default constructed
- 2
- Destructed
- ********************************************************
- GetRoute(); !!!!!!!!!!!!!!!!!!!!!!!!!
- cout << 2 << "\n"; !!!!!!!!!!!!!!!!!!!!!!!!!
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement