'Two input types - Initializer list (C++)

I need the instance str is able to accept two diferent types. I have to use notation with {}. It should be std::initializer_list.

const UTF8String str{ };

This works:

class UTF8String {

public:
    std::string inputString;
};

int main() {    
    
    const UTF8String str{ "hello" };

    return 0;
}

This works:

class UTF8String {

public:
    int inputInt;
};

int main() {    
    const UTF8String str{ 5 };

    return 0;
}

But this doesn't work:

class UTF8String {

public:
    std::string inputString;
    int inputInt;
};

int main() {    
    
    const UTF8String str{ "hello" };
    const UTF8String str{ 5 };

    return 0;
}
c++


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source