1

Good Day,

I have a String Library which is great, but is missing many features that I need. I wish to extend it to add more functionality. The code for the String library "WString.h" is given in this link.

https://github.com/arduino/Arduino/blob/master/hardware/arduino/cores/arduino/WString.h

I wished to write new functions but dont want to modify WString.h as that is part of the library. Hence, I wrote something like this:

class StringW: public String{

public:
StringW();
};  

However, upon doing this:

StringW myString="asd";

I get the error:

Error 1 conversion from 'const char [4]' to non-scalar type 'StringW' requested

Can I know why this occurs? My C++ knowledge is still quite flaky. Shouldn't the child class automatically inherit parent classes functions, including the = operator overload? How can I make my child class String class see the = operator in the parent class as part of the contructor?!

soulslicer0
  • 69
  • 2
  • 8
  • .cpp looks like this StringW::StringW():String(){ } – soulslicer0 Jun 23 '13 at 04:48
  • possible duplicate of [C++: Inheritance and Operator Overloading](http://stackoverflow.com/questions/3410688/c-inheritance-and-operator-overloading) – Rubens Jun 23 '13 at 04:54
  • Note that your `String` class does not have a virtual destructor. This means that it is probably not a good idea to inherit from it at all. You can still do so if you really want, but as soon as you `delete` in a polymorphic context you will [get into trouble](http://stackoverflow.com/questions/461203/when-to-use-virtual-destructors). – ComicSansMS Jun 23 '13 at 07:15

0 Answers0