Skip to content
Next Next commit
Rule of three: if you have a custom destructor, then you probably nee…
…d a custom copy constructor and a custom copy assignment operator.
  • Loading branch information
James Foster committed Aug 19, 2021
commit f8ab8b85f783bec9462f740e292f707b02222e68
7 changes: 7 additions & 0 deletions SampleProjects/TestSomething/test/clientServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ unittest(Client) {
assertEqual(outData + "\r\n", inData);
}

unittest(Client_copy_constructor) {
Client client1;
Client client2;
client2 = client1;
assertTrue(true);
}

unittest(IPAddress) {
IPAddress ipAddress0;
assertEqual(0, ipAddress0.asWord());
Expand Down
14 changes: 14 additions & 0 deletions cpp/arduino/Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@ class Client : public Stream {
mGodmodeDataIn = new String;
}
}
Client(const Client &client) {
// copy constructor
if (mGodmodeDataIn) {
mGodmodeDataIn = new String(mGodmodeDataIn->c_str());
}
std::cout << __FILE__ << ":" << __LINE__ << std::endl;
}
Client & operator=(const Client &client) {
// copy assignment operator
if (mGodmodeDataIn) {
mGodmodeDataIn = new String(mGodmodeDataIn->c_str());
}
return *this;
}
~Client() {
if (mGodmodeDataIn) {
delete mGodmodeDataIn;
Expand Down