变量具有不完整的类型 std::string;string.h 有很多错误 [英] variable has incomplete type std::string; string.h has many errors

查看:36
本文介绍了变量具有不完整的类型 std::string;string.h 有很多错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

字符串有问题.我已经使用它们数周没有问题了,但是周一到一半时,我开始遇到奇怪的问题:[Clang IntelliSense] 错误:变量的类型不完整 'std::string'每当我尝试制作字符串时.当我尝试 wstringostringstream 而不是 stringstream 时会发生类似的错误.初始化 std::string* s 也可以正常工作,但是 s->append(...) 导致 "member 可以访问不完整的类型 'std::string'"

这一切都是因为 Visual Studio (VS) 突然无法找到一些我使用了数周的 #includes,包括一些标准库(不记得是哪个,因为....).我通过让 VS 搜索正确的文件解决了这个问题,它找到了一些文件(不确定它们是与以前相同还是不同),因此 #include 语句不再有问题,但现在我有这个问题.

我已经使用 好几个星期了.在研究这个问题时,我读到 是错误的文件,所以我尝试了 #include 但没有区别.我已经尝试过 但也没有区别.

我检查了我的外部依赖项,string.h 有几十个错误,我认为这很奇怪,因为它是我没有接触过的标准文件.

我使用的是 VS2015、GNU make,我看到了 Clang IntelliSense,但我也在这里看到了一些 g++,所以我不确定它实际使用的是什么编译器.也使用visualGDB 5.3.如果我忘记了什么,请告诉我.

#include #include <字符串>#include int main(int argc, char *argv[]){std::string message =取消注释";...

消息

是突出显示有问题的部分(不完整类型)

std::wstring wideMessage;

也是不完整的类型

  • 预期结果:没有像过去几周那样的问题.我能够声明,初始化,追加(),无论如何
  • 实际结果:无法编译/调试
  • 错误:变量具有不完整的类型std::string"变量具有不完整的类型std::wstring"没有用于初始化std::ostringstream"的匹配构造函数

我在这里看到了许多类似的问题,但所有问题都与前向声明有关,我看不出这与此有什么关系.我对类、结构或函数没有任何问题;甚至在 main() 中声明一个变量也是有问题的

基于这个答案,很可能使用 VC++ 14.0 作为编译器,但我不知道如何确定

编辑 2:错误信息:

1>VisualGDB:发送 45 个更新的源文件来构建机器......1>VisualGDB:运行make CONFIG=Debug";在目录/tmp/VisualGDB/c/Users/pthien/VS/Whatever/Whatever"中在 pthien@buildserver (SSH)1>/opt/poky/1.8/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-g++ -march=armv7-a -mfloat-abi=hard -mfpu=neon -mtune=cortex-a8 --sysroot=/opt/poky/1.8/sysroots/cortexa8hf-vfp-neon-poky-linux-gnueabi -ggdb -ffunction-sections -O0 -std=c++11 -march=armv7-a -mfloat-abi=hard -mfpu=neon -mtune=cortex-a8 --sysroot=/opt/poky/1.8/sysroots/cortexa8hf-vfp-neon-poky-linux-gnueabi -ggdb -ffunction-sections -O0 -I/opt/poky/1.8/sysroots/cortexa8hf-vfp-neon-poky-linux-gnueabi/usr/include -I/opt/googletest-master/googletest/include -I/opt/boost_1_61_0 -I../../cereal/cereal-1.2.2/cereal-1.2.2/include -I/opt/poky/1.8/sysroots/cortexa8hf-vfp-neon-poky-linux-gnueabi/usr/websocketpp-master -I/opt/poky/1.8/sysroots/cortexa8hf-vfp-neon-poky-linux-gnueabi/usr/include/websocketpp -I/opt/curl-7.54.0 -I/opt/boost_1_61_0/boost -I/opt/poky/1.8/sysroots/cortexa8hf-vfp-neon-poky-linux-gnueabi/usr/include/easywsclient-master -I/opt/poky/1.8/sysroots/cortexa8hf-vfp-neon-poky-linux-gnueabi/usr/include/uWebSockets-master -I/opt/poky/1.8/sysroots/cortexa8hf-vfp-neon-poky-linux-gnueabi/usr/include/c++/4.9.2/experimental -I/opt/boost_1_61_0/boost/tr1/tr1 -I/opt/boost_1_61_0/tools/build/src/engine -I/opt/poky/1.8/sysroots/cortexa8hf-vfp-neon-poky-linux-gnueabi/usr/include/c++/4.9.2 -I/opt/curl-7.54.0/include -I/opt/poky/1.8/sysroots/cortexa8hf-vfp-neon-poky-linux-gnueabi/usr/include/cereal -I/opt/poky/1.8/sysroots/x86_64-pokysdk-linux/usr/lib/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/4.9.2/include-fixed -I/opt/boost_1_61_0/boost/compatibility/cpp_c_headers -我../../../../../Program -IFiles -I(x86)/Microsoft -IVisual -IStudio -I10.0/VC/crt/src"-I../../../../../Program -IFiles -I(x86)/Microsoft -IVisual -IStudio -I14.0/VC/include"-I/opt/poky/1.8/sysroots/cortexa8hf-vfp-neon-poky-linux-gnueabi/usr/include/c++/4.9.2/arm-poky-linux-gnueabi -DDEBUG -c What.cpp -o 调试/Whatever.o -MD -MF 调试/Whatever.dep1>C:\Users\pthien\AppData\Local\VisualGDB\RemoteSourceCache\buildserver\0008\include\wchar.h(459,20):注意:'wcstold'1>extern long double wcstold (const wchar_t *__restrict __nptr,1>^1>无论.cpp:在函数'int main(int,char**)'中:1>C:\Users\pthien\VS\Whatever\Whatever\Whatever.cpp(138,47): 错误 : 'strlen' 未在此范围内声明1>size_t request_len = strlen(webSocketRequest);1>^1>Makefile:160: 目标 'Debug/Whatever.o' 的配方失败1>make: *** [Debug/Whatever.o] 错误 11>-------------------------------------------------------------1>命令以代码 2 退出1>可执行:制作1>参数:CONFIG=调试1>目录:/tmp/VisualGDB/c/Users/pthien/VS/Whatever/Whatever1>VisualGDB:错误:命令行操作失败1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.MakeFile.Targets(37,5): 错误 MSB3073: 命令"C:\Program Files (x86))\Sysprogs\VisualGDB\\VisualGDB.exe"/build "C:\Users\pthien\VS\Whatever\Whatever\Whatever.vcxproj";/solution:C:\Users\pthien\VS\Whatever\Whatever.sln"/config:Debug"/平台:Win32""以代码 1 退出.========== 构建:0 成功,1 失败,0 最新,0 跳过 ==========

这大约是输出的 10%,包括开头和结尾.奇怪的是 strlen() 的问题.它在 IDE 中没有下划线,所以我不知道它有问题.这是有道理的,因为我为 strlen() 注释掉了 #include 就是其中之一.

解决方案

通过从我的目录列表中删除一个未使用的库然后 重新加载所有目录.我不相信任何事情都解决了,因为重新加载目录会产生随机结果.有时它会解决问题,有时它会导致新的问题.就在昨天,我重新加载,然后无法找到 system.h 和 time.h(不记得名称).我正在排除故障,但几个小时后问题消失了.反正我发布了一个后续问题这里

Something is very wrong with strings. I have been using them for weeks without issue, but halfway through Monday, I started having strange issues: [Clang IntelliSense] Error: variable has incomplete type 'std::string' whenever I try to make a string. similar errors occur when I try wstring and ostringstream, but not stringstream. initializing std::string* s also works fine but s->append(...) results in"member has access into incomplete type 'std::string'"

This all came about because visual studio (VS) was all of a sudden unable to find some #includes that I have had for weeks, including some standard libraries (don't remember which because...). I solved that by having VS search for the correct files and it found some files (unsure if they're the same as before or different) so it no longer has an issue with the #include statements but now I have this issue.

I had been using <string.h> fine for weeks. while researching this issue, I read that <string.h> is the wrong file to use so I've tried #include <string> but there is no difference. I've since tried <strings.h> and <cstring> but no difference there either.

I checked out my external dependencies and string.h has dozens of errors, which I thought is weird because it's a standard file that I haven't touched.

I'm using VS2015, GNU make, and I see Clang IntelliSense but I also see some g++ here so I'm not sure what compiler it's actually using. also using visualGDB 5.3. let me know if I forgot anything.

#include <iostream>
#include <string>
#include <sstream>
int main(int argc, char *argv[])
{
std::string message = "uncomment";
...

message

is the part that is highlighted as having an issue (incomplete type)

std::wstring wideMessage;

also incomplete type

  • expected results: no problems like the past few weeks. I was able to declare, initialize, append(), whatever
  • actual results: can't compile/debug
  • errors: variable has incomplete type 'std::string' variable has incomplete type 'std::wstring' no matching constructor for initialization of 'std::ostringstream'

I see many similar issues here, but all the issues have to do with forward declaration and I don't see what that has to do with this. I'm not having any issues with classes, structs, or functions; even declaring a variable in main() is problematic

edit: based on this answer, it is likely using VC++ 14.0 as a compiler but I do not know how to tell for sure

edit 2: error message:

1>  VisualGDB: Sending 45 updated source files to build machine...
1>  VisualGDB: Run "make  CONFIG=Debug" in directory "/tmp/VisualGDB/c/Users/pthien/VS/Whatever/Whatever" on pthien@buildserver (SSH)
1>  /opt/poky/1.8/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-g++ -march=armv7-a -mfloat-abi=hard -mfpu=neon -mtune=cortex-a8 --sysroot=/opt/poky/1.8/sysroots/cortexa8hf-vfp-neon-poky-linux-gnueabi -ggdb -ffunction-sections -O0 -std=c++11 -march=armv7-a -mfloat-abi=hard -mfpu=neon -mtune=cortex-a8 --sysroot=/opt/poky/1.8/sysroots/cortexa8hf-vfp-neon-poky-linux-gnueabi -ggdb -ffunction-sections -O0 -I/opt/poky/1.8/sysroots/cortexa8hf-vfp-neon-poky-linux-gnueabi/usr/include -I/opt/googletest-master/googletest/include -I/opt/boost_1_61_0 -I../../cereal/cereal-1.2.2/cereal-1.2.2/include -I/opt/poky/1.8/sysroots/cortexa8hf-vfp-neon-poky-linux-gnueabi/usr/websocketpp-master -I/opt/poky/1.8/sysroots/cortexa8hf-vfp-neon-poky-linux-gnueabi/usr/include/websocketpp -I/opt/curl-7.54.0 -I/opt/boost_1_61_0/boost -I/opt/poky/1.8/sysroots/cortexa8hf-vfp-neon-poky-linux-gnueabi/usr/include/easywsclient-master -I/opt/poky/1.8/sysroots/cortexa8hf-vfp-neon-poky-linux-gnueabi/usr/include/uWebSockets-master -I/opt/poky/1.8/sysroots/cortexa8hf-vfp-neon-poky-linux-gnueabi/usr/include/c++/4.9.2/experimental -I/opt/boost_1_61_0/boost/tr1/tr1 -I/opt/boost_1_61_0/tools/build/src/engine -I/opt/poky/1.8/sysroots/cortexa8hf-vfp-neon-poky-linux-gnueabi/usr/include/c++/4.9.2 -I/opt/curl-7.54.0/include -I/opt/poky/1.8/sysroots/cortexa8hf-vfp-neon-poky-linux-gnueabi/usr/include/cereal -I/opt/poky/1.8/sysroots/x86_64-pokysdk-linux/usr/lib/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/4.9.2/include-fixed -I/opt/boost_1_61_0/boost/compatibility/cpp_c_headers -I"../../../../../Program -IFiles -I(x86)/Microsoft -IVisual -IStudio -I10.0/VC/crt/src" -I"../../../../../Program -IFiles -I(x86)/Microsoft -IVisual -IStudio -I14.0/VC/include" -I/opt/poky/1.8/sysroots/cortexa8hf-vfp-neon-poky-linux-gnueabi/usr/include/c++/4.9.2/arm-poky-linux-gnueabi -DDEBUG  -c Whatever.cpp -o Debug/Whatever.o -MD -MF Debug/Whatever.dep
1>  C:\Users\pthien\AppData\Local\VisualGDB\RemoteSourceCache\buildserver\0008\include\wchar.h(459,20): note :    'wcstold'
1>   extern long double wcstold (const wchar_t *__restrict __nptr,
1>                      ^
1>  Whatever.cpp: In function 'int main(int, char**)':
1>C:\Users\pthien\VS\Whatever\Whatever\Whatever.cpp(138,47): error : 'strlen' was not declared in this scope
1>     size_t request_len = strlen(webSocketRequest);
1>                                                 ^
1>  Makefile:160: recipe for target 'Debug/Whatever.o' failed
1>  make: *** [Debug/Whatever.o] Error 1
1>  -------------------------------------------------------------
1>  Command exited with code 2
1>  Executable: make
1>  Arguments:  CONFIG=Debug
1>  Directory: /tmp/VisualGDB/c/Users/pthien/VS/Whatever/Whatever
1>VisualGDB : error : Command-line action failed
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.MakeFile.Targets(37,5): error MSB3073: The command ""C:\Program Files (x86)\Sysprogs\VisualGDB\\VisualGDB.exe" /build "C:\Users\pthien\VS\Whatever\Whatever\Whatever.vcxproj" "/solution:C:\Users\pthien\VS\Whatever\Whatever.sln"  "/config:Debug" "/platform:Win32"" exited with code 1.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

This is about 10% of the output, including the beginning and the end. What's weird is the issue with strlen(). It is not underlined in the IDE, so I had no idea there was an issue with it. It makes sense because I commented out the #include for <string.h>and <cstring> and strlen() is in one of those.

解决方案

managed to avoid this issue, but probably not solve the still-unknown underlying issue, by removing an unused library from my list of directories and then reloading all directories. I'm not convinced anything was solved because reloading directories gives random results. sometimes it fixes issues and sometimes it causes new ones. Just yesterday, I reloaded and it was then unable to find system.h and time.h (don't remember the names). I was troubleshooting that but the issue disappeared a few hours later. anyway I posted a follow-up question here

这篇关于变量具有不完整的类型 std::string;string.h 有很多错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆