错误:无法传递非平凡类型'std :: string'的对象以及更多错误

问题描述 投票:0回答:1

我正在Travis CI中运行构建,并且在编译期间会发生此错误。我尝试指定C ++编译器并尝试使用g ++,但这导致了更多错误。

$ clang -I ./jsoncpp/include/ -L ./jsoncpp/build/debug/lib -std=c++14 -v test.cpp -o buildtest.exe
...
./IBMWatson.h:79:44: error: cannot pass object of non-trivial type 'std::string'
      (aka 'basic_string<char>') through variadic function; call will abort at
      runtime [-Wnon-pod-varargs]
                curl_easy_setopt(curl, CURLOPT_PASSWORD, apikey); /* Par...
                                                         ^
./IBMWatson.h:81:39: error: cannot pass object of non-trivial type 'std::string'
      (aka 'basic_string<char>') through variadic function; call will abort at
      runtime [-Wnon-pod-varargs]
                curl_easy_setopt(curl, CURLOPT_URL, url); /* Sets Regio...
                                                    ^
./IBMWatson.h:104:102: warning: result of comparison against a string literal is
      unspecified (use strncmp instead) [-Wstring-compare]
  ...+ response.length(), &root, &err) || funcName == "returnVoices" || funcN...
...
4 warnings and 4 errors generated.
The command "clang -I ./jsoncpp/include/ -L ./jsoncpp/build/debug/lib -std=c++14 -v test.cpp -o buildtest.exe" exited with 1.
c++ clang c++14 travis-ci clang++
1个回答
0
投票

curl_easy_setopt是C函数,其中variadic实际上是指<cstdarg>...参数。它只接受普通类型,std::string不是(即,不能用memcpy复制,而是涉及到非普通的复制构造函数);否则,行为是不确定的或仅有条件地支持。为了传递字符串值,请使用通过const char*获得的c_str()表示形式:

curl_easy_setopt(curl, CURLOPT_PASSWORD, apikey.c_str());
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
© www.soinside.com 2019 - 2024. All rights reserved.