/* An Error example, How NOT to return a SafeString by Matthew Ford Copyright(c)2020 Forward Computing and Control Pty. Ltd. This example code is in the public domain. install the SafeString library from the Arduino Library manager or download and install the SafeString zip file from www.forward.com.au/pfod/ArduinoProgramming/SafeString/index.html */ #include "SafeString.h" int count = 0; void setup() { Serial.begin(9600); for (int i = 10; i > 0; i--) { Serial.print(' '); Serial.print(i); delay(500); } Serial.println(); Serial.println(F("This example tries to pass back a SafeString object as a return. It does not compile and give the error message")); Serial.println(F(" SafeString(const SafeString& other ); // You must declare SafeStrings function arguments as a reference, SafeString&, e.g. void test(SafeString& strIn)")); } SafeString loopCountStr(int num) { createSafeString(str, 40, "loop count = "); // create a SafeString str += num; // update it return str; // try and return it } void loop() { count = 1; Serial.println(loopCountStr(count)); // try and print result Serial.println(F(" Finished")); while (1) { } // stop here }