C ++ inline method of base class should be explicitly allowed?

I had a strange problem with inheriting and resolving a method in my class hierarchy. The code is compiled using clang ++ 5.0 s -O0. I have two classes:

class PrintBase
{
protected:
    static wstring_convert<codecvt_utf8<wchar_t>> sConverter;

public:
    virtual void PrintChar(wchar_t ch) = 0;
    inline  void PrintChar(char ch)
    {
        PrintChar(sConverter.from_bytes(ch)[0]);
    }

    virtual void PrintString(const wstring& str) = 0;
    inline  void PrintString(const string& str)
    {
        PrintString(sConverter.from_bytes(str));
    }
};

class Print: public PrintBase
{
public:
    virtual void PrintChar(wchar_t ch) override;
    virtual void PrintString(const wstring& str) override;
};

void Print::PrintChar(wchar_t ch)
{
    // do stuff
}

void Print::PrintString(const wstring& str)
{
    // do stuff
}

If I build a print instance Print* pnt = new Print();and call pnt->PrintChar('c');, it will correctly call the built-in base class method, perform the conversion, and then correctly call the implemented virtual override in the derived class.

If I call pnt->PrintString("test");or pnt->PrintString(string("test"));or pnt->PrintString(someString);, I get an error:

No viable conversion from 'basic_string<char, char_traits<char>, allocator<char>>' to 'const basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t>>'

... with some variation on a constant of type "from". A call pnt->PrintString(L"test");or the like will work as you would expect. And I can make it call the inline string & withpnt->PrintBase::PrintString("test");

inline char , & ?

+3
1

, .

, . , PrintString Print::PrintString PrintBase::PrintString, , .

- , using:

class Print: public PrintBase
{
public:
    virtual void PrintChar(wchar_t ch) override;
    using PrintBase::PrintChar;

    virtual void PrintString(const wstring& str) override;
    using PrintBase::PrintString;
};

, PrintChar('x') Print . wchar_t char, . , , ?

+5

All Articles