Boost logo

Boost Users :

From: Greg Schmid (gregs_at_[hidden])
Date: 2008-04-01 15:55:13


I have a string class (tstring) which takes care of narrow <=> wide string
conversions, and which provides operators for conversion to std::string and
std::wstring:

    operator std::wstring &();
    operator std::string &();
    operator const std::wstring &() const;
    operator const std::string &() const;

In Boost 1.33, I could do the following:

    boost::filesystem::path dir ("/foo");
    tstring file ("bar");
    boost::filesystem::path p = dir / file;

In Boost 1.35, this no longer works; VS8 gives error C2679: binary '/' : no
operator found which takes a right-hand operand of type 'const tstring' (or
there is no acceptable conversion). However, if I change it to

    boost::filesystem::path p = dir;
    p /= file;

then all is well. Also,

    boost::filesystem::path p = dir / std::string(file);
    boost::filesystem::path p = dir / boost::filesystem::path(file);

work just fine.

I don't understand the C++ type conversion rules well enough to understand why
the conversion to std::string can happen automatically with operator/= but not
operator/. I'd rather not have to specify the cast, as the original form of the
code is much cleaner.

Suggestions?

Greg Schmidt (gregs_at_[hidden])
Trawna Publications


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net