Cast on pass to function

Viewed 31

Is there a way to cast and object/variable passed to a function without modification to / overloading of the function itself? IE only modification to the class the parameter should be casted to?

simple example:

class String
{
public:
    String(const char* newChars);

    char* get();
    void set(char* newChars);

private:
    char* chars;
}
class StringList
{
public:
    StringList();

    void push(String string);

private:
    String stringList[10];
}
int main()
{
    StringList list;
    list.push("string literal");
    return 0;
}

In this example I'd like to modify the String class to make it so if I pass a const char* to the StringList's push function (only adding a String to the array), it knows to cast the const char* to a String. Ideally without modification to StringList.

0 Answers
Related