我在这些代码行上遇到了一个奇怪的分段错误。
OutputHandler(std::string const& path) throw(std::exception);
MyClass::MyClass()
: basepath(boost::filesystem::canonical("./").string() + "/"),
outputHandler(basepath + "log.log") {} // Error traces back to this line (line 11)
分割错误:
#0 0x00007ffff6fd512b in std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::string const&) ()
from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#1 0x0000000000423bd7 in std::operator+<char, std::char_traits<char>, std::allocator<char> > (__lhs=..., __rhs=0x4659a1 "log.log")
at /usr/include/c++/4.8/bits/basic_string.h:2405
#2 0x0000000000414466 in MyClass::MyClass (this=0x7fffffffd6f0) at ./source/MyClass.cpp:11
#3 0x0000000000464a28 in main () at ./source/main.cpp:10
是什么导致了这个错误,我该如何解决?我猜在转换basepath + "log.log"
为 a时出了点问题std::string
?