Skip to content

Instantly share code, notes, and snippets.

@drodil
Last active May 30, 2018 20:53
Show Gist options
  • Save drodil/141a073c986e745ddeca5cb5a952b1ae to your computer and use it in GitHub Desktop.
Save drodil/141a073c986e745ddeca5cb5a952b1ae to your computer and use it in GitHub Desktop.
Copy constructor derp
#include <string>
class CarDoor {
public:
explicit CarDoor(const std::string& name) : mName(name) { }
~CarDoor() = default;
// Let's imagine a lot of functions here
// Copy constructor
CarDoor(const CarDoor& other) : mName(other.mName) { }
// Copy assignment operator
CarDoor& operator=(const CarDoor& other) {
mName = other.mName;
return *this;
}
private:
std::string mName;
};
#include <string>
class CarDoor {
public:
CarDoor(const std::string& name, std::uint16_t numWindows) : mName(name), mNumWindows(numWindows) { }
~CarDoor() = default;
// Let's imagine a lot of functions here
// Copy constructor
CarDoor(const CarDoor& other) : mName(other.mName) { }
// Copy assignment operator
CarDoor& operator=(const CarDoor& other) {
mName = other.mName;
return *this;
}
private:
std::string mName;
// WE NEED NEW MEMBER VARIABLE TO CHECK HOW MANY WINDOWS THIS DOOR HAS
std::uint8_t mNumWindows
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment