在最近创建的项目中,我在尝试make
时遇到此错误:
注意:params.h:11
只是#include <string>
Building file: ../src/cmds/params.cpp
Invoking: Cross G++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/cmds/params.d" -MT"src/cmds/params.d" -o "src/cmds/params.o" "../src/cmds/params.cpp"
In file included from /usr/include/c++/4.8/bits/char_traits.h:39:0,
from /usr/include/c++/4.8/string:40,
from ../src/cmds/params.h:11,
from ../src/cmds/params.cpp:8:
/usr/include/c++/4.8/bits/stl_algobase.h: In instantiation of ‘static _OI std::__copy_move<false, false, std::random_access_iterator_tag>::__copy_m(_II, _II, _OI) [with _II = char*; _OI = std::ostream_iterator<std::basic_string<char> >]’:
/usr/include/c++/4.8/bits/stl_algobase.h:390:70: required from ‘_OI std::__copy_move_a(_II, _II, _OI) [with bool _IsMove = false; _II = char*; _OI = std::ostream_iterator<std::basic_string<char> >]’
/usr/include/c++/4.8/bits/stl_algobase.h:428:38: required from ‘_OI std::__copy_move_a2(_II, _II, _OI) [with bool _IsMove = false; _II = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >; _OI = std::ostream_iterator<std::basic_string<char> >]’
/usr/include/c++/4.8/bits/stl_algobase.h:460:17: required from ‘_OI std::copy(_II, _II, _OI) [with _II = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >; _OI = std::ostream_iterator<std::basic_string<char> >]’
../src/cmds/params.cpp:96:81: required from here
/usr/include/c++/4.8/bits/stl_algobase.h:335:18: error: invalid user-defined conversion from ‘char’ to ‘const std::basic_string<char>&’ [-fpermissive]
*__result = *__first;
^
In file included from /usr/include/c++/4.8/string:53:0,
from ../src/cmds/params.h:11,
from ../src/cmds/params.cpp:8:
/usr/include/c++/4.8/bits/basic_string.tcc:212:5: note: candidate is: std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*, const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>] <near match>
basic_string<_CharT, _Traits, _Alloc>::
^
/usr/include/c++/4.8/bits/basic_string.tcc:212:5: note: no known conversion for argument 1 from ‘char’ to ‘const char*’
In file included from /usr/include/c++/4.8/bits/char_traits.h:39:0,
from /usr/include/c++/4.8/string:40,
from ../src/cmds/params.h:11,
from ../src/cmds/params.cpp:8:
/usr/include/c++/4.8/bits/stl_algobase.h:335:18: error: invalid conversion from ‘char’ to ‘const char*’ [-fpermissive]
*__result = *__first;
^
In file included from /usr/include/c++/4.8/string:53:0,
from ../src/cmds/params.h:11,
from ../src/cmds/params.cpp:8:
/usr/include/c++/4.8/bits/basic_string.tcc:212:5: error: initializing argument 1 of ‘std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*, const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’ [-fpermissive]
basic_string<_CharT, _Traits, _Alloc>::
^
make: *** [src/cmds/params.o] Error 1
可能是什么原因?
答案 0 :(得分:1)
以下错误在这里很重要
/usr/include/c++/4.8/bits/stl_algobase.h:335:18:
error: invalid user-defined conversion from ‘char’ to ‘const std::basic_string<char>&’ [-fpermissive]
*__result = *__first;
这表示您的程序中某处正在尝试将 char 转换为 std :: string 是不可能的。