I have a String class which has a member std::string. One of the constructor is
String (std::string s)
{
// member: std::string _mString;
_mString = s; // error on path assignment
}
I now have functions that take String as parameter, e.g. Load(String path);
but it turns out that boost::filesystem::path::string() is incompatible with that String constructor, yet, normally assigning is ok
boost::filesystem::path somepath("some directory")
std::string filename = somepath.extension(); // OK!
What is happening? How can I make my constructor work? Thanks.
EDIT: Issue solved by making it const ref, but still curious why the error because it seems ok to pass a copy since it can be assigned directly. Error in file xstring
void __CLR_OR_THIS_CALL _Tidy(bool _Built = false,
size_type _Newsize = 0)
{ // initialize buffer, deallocating any storage
if (!_Built)
;
else if (_BUF_SIZE <= _Myres)
{ // copy any leftovers to small buffer and deallocate
_Elem *_Ptr = _Bx._Ptr;
if (0 < _Newsize)
_Traits_helper::copy_s<_Traits>(_Bx._Buf, _BUF_SIZE, _Ptr, _Newsize);
_Mybase::_Alval.deallocate(_Ptr, _Myres + 1);
}
_Myres = _BUF_SIZE - 1; // **** ERROR ***
_Eos(_Newsize);
}
in your constructor: String (std::string s)
should be String (const std::string& s)