boost::filesystem::path 和 std::string
我有一个 String 类,它有一个成员 std::string 。构造函数之一是
String (std::string s)
{
// member: std::string _mString;
_mString = s; // error on path assignment
}
我现在有以 String 作为参数的函数,例如 Load(String path);
但事实证明 boost::filesystem::path::string() 与 String 构造函数不兼容,但是通常分配是可以的
boost::filesystem::path somepath("some directory")
std::string filename = somepath.extension(); // OK!
发生了什么?我怎样才能让我的构造函数工作?谢谢。
编辑:通过将其设置为 const ref 解决了问题,但仍然好奇为什么会出现错误,因为传递副本似乎可以,因为它可以直接分配。 文件 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);
}
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);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在构造函数中:
String (std::string s)
应该是String (const std::string& s)
in your constructor:
String (std::string s)
should beString (const std::string& s)