
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@trawna.com) Trawna Publications

[Please do not mail me a copy of your followup]
boost-users@lists.boost.org spake the secret code
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;
I used to think that implicit conversions were great, until I read "C++ Coding Standards: 101 Rules, Guidelines, and Best Practices" by Sutter and Alexandrescu. Now I eschew implicit conversions and use an explicit conversion where needed. I know that doesn't really answer your question about why it used to work and why it doesn't anymore, but had you written the code with an explicit conversion to std::string, it would have worked before and would still work now. I guess that shows the wisdom of why implicit conversions should be avoided... -- "The Direct3D Graphics Pipeline" -- DirectX 9 draft available for download http://www.xmission.com/~legalize/book/download/index.html Legalize Adulthood! http://blogs.xmission.com/legalize/
participants (2)
-
Greg Schmid
-
legalize+jeeves@mail.xmission.com