On Thu, Oct 24, 2002 at 10:07:33AM +0200, Jean-Marc Lasgouttes wrote: > Just to satisfy my curiosity, would something like that work?
In most cases probably yes (if this is the only "user defined conversion" involved). > lyxstring::lyxstring(std::string const &str) > { > //what should I put here? Can I call the char const * constructor? > } No, you have to copy the code or call some comon init() function. > Of course, one has to #include <string> always to make it work, and > this could be costly. That's probably true. > Would the following hack work? > > template<class strclass> > lyxstring::lyxstring(T const &str) > { > // use str.c_str() here, which will break of course if T is not > // std::string... > } Probably too permissive as this allows to convert any type to lyxstring... Another way out would be to have a "stringfwd" much like the standard "iosfwd". g++ 3.1 uses such a thing internally as I have just noticed: namespace std { template<class _CharT> struct char_traits; template<> struct char_traits<char>; #ifdef _GLIBCPP_USE_WCHAR_T template<> struct char_traits<wchar_t>; #endif template<typename _Alloc> class allocator; template<typename _CharT, typename _Traits = char_traits<_CharT>, typename _Alloc = allocator<_CharT> > class basic_string; typedef basic_string<char> string; typedef basic_string<wchar_t> wstring; } Having such a header would benefit all over the place, especially the inset bases would not need to include a 2000 line header (that made a difference of more then 10% IIRC last time I checked for mathed). It would take a bit of configure magic to get this working across all platforms. Well. Using g++-v3/bits/stringfwd.h if available and <string> everywhere else would do for starters... Andre' -- Those who desire to give up Freedom in order to gain Security, will not have, nor do they deserve, either one. (T. Jefferson)