W
woodbrian77
Notice the operator<< functions here:
class failure : public ::std::exception {
::std::string whatStr;
public:
explicit failure (char const* what_) : whatStr(what_)
{}
explicit failure
:std::string what_) : whatStr
:std::move(what_))
{}
~failure () throw()
{}
char const* what () const throw()
{ return whatStr.c_str(); }
// failure& operator<< (char* s)
// {
// whatStr.append(s);
// return *this;
// }
failure& operator<< (char const* s)
{
whatStr.append(s);
return *this;
}
failure& operator<<
:std::string const& s)
{
whatStr.append(s);
return *this;
}
template <class T>
failure& operator<< (T val)
{
whatStr.append
:std::to_string(val));
return *this;
}
};
If I add back the commented out operator<< above the
following line is accepted by the compiler:
if(argc!=2) throw failure("Usage: ")<<*argv<<" config-file-name";
But if it is stays commented out, I get an error:
/ErrorWords.hh: In instantiation of ‘cmw::failure& cmw::failure:
perator<<(T) [with T = char*]’:
cmwAmbassador.cc:309:44: required from here
../ErrorWords.hh:47:40: error: call of overloaded ‘to_string(char*&)’ isambiguous
whatStr.append
:std::to_string(val));
I'd like to be able to remove the commented out version
of that operator from the class. I guess the compiler
prefers the function template version to the version that
takes a char const*. Any ideas? Thanks.
Brian
Ebenezer Enterprises - In G-d we trust.
http://webEbenezer.net
class failure : public ::std::exception {
::std::string whatStr;
public:
explicit failure (char const* what_) : whatStr(what_)
{}
explicit failure
{}
~failure () throw()
{}
char const* what () const throw()
{ return whatStr.c_str(); }
// failure& operator<< (char* s)
// {
// whatStr.append(s);
// return *this;
// }
failure& operator<< (char const* s)
{
whatStr.append(s);
return *this;
}
failure& operator<<
{
whatStr.append(s);
return *this;
}
template <class T>
failure& operator<< (T val)
{
whatStr.append
return *this;
}
};
If I add back the commented out operator<< above the
following line is accepted by the compiler:
if(argc!=2) throw failure("Usage: ")<<*argv<<" config-file-name";
But if it is stays commented out, I get an error:
/ErrorWords.hh: In instantiation of ‘cmw::failure& cmw::failure:
cmwAmbassador.cc:309:44: required from here
../ErrorWords.hh:47:40: error: call of overloaded ‘to_string(char*&)’ isambiguous
whatStr.append
I'd like to be able to remove the commented out version
of that operator from the class. I guess the compiler
prefers the function template version to the version that
takes a char const*. Any ideas? Thanks.
Brian
Ebenezer Enterprises - In G-d we trust.
http://webEbenezer.net