草庐IT

non-struct

全部标签

C++:struct 和 new 关键字

我是C++的初学者,我有以下代码:structAirline{stringName;intdiameter;intweight;};Airline*myPlane=newAirline;我的问题是,如果我没记错的话,当我调用new方法时,它会分配内存。PC如何知道要分配多少内存,特别是考虑到其中有一个字符串类型?谢谢 最佳答案 std::string对象是固定大小的;它包含一个指向实际字符缓冲区的指针及其长度。std::string的定义看起来像classstring{char*buffer;size_tnchars;public:

c++ - 从 struct timespec 转换为 std::chrono::?

我有一个structtimespec值流。我想将它们转换为nativeC++11表示,但我完全被chrono打败了。什么是最佳目的​​地以及如何从structtimespec或structtimeval到达那里,因为这是一个简单的转换,微秒对这些计时来说已经足够了?我想我想了解这个,对吧?std::chrono::system_clock::time_point在这种情况下,timespec是来自GPS的UNIX时间。是的,他们正在使用4字节秒(转换后的形式在内存中签名,然后写成无符号),到2038年将被确定。作为引用,我将把它添加到gsf的C++阅读器中

c++ - 重定义struct报错,我只定义了一次

我真的不明白如何修复这个重定义错误。编译+错误g++main.cpplist.cppline.cppInfileincludedfromlist.cpp:5:0:line.h:2:8:error:redefinitionofâstructLineâline.h:2:8:error:previousdefinitionofâstructLineâmain.cpp#includeusingnamespacestd;#include"list.h"intmain(){intno;//Listlist;cout>no;//list.set(no);//list.display();}list.

c++ - 将 NON-POD 类型传递给 Variadic 函数是未定义的行为?

Inthisdocument,作者说OnlyaPOD-typecanbeanargumentfortheellipsis"..."whilestd::stringisnotaPOD-type.我将此理解为将NON-POD类型传递给Variadic函数是未定义的行为。对吗?不过,他是在说C/C++标准吗?我试图在n3242C++规范中找到它。但是找不到。我想知道我的理解是否正确,这是一个标准。 最佳答案 它在C++115.2.2/7中指定:Passingapotentially-evaluatedargumentofclasstype

C++11 "Non-movable"类型

这个问题在这里已经有了答案:关闭9年前。PossibleDuplicate:WhydoC++11-deletedfunctionsparticipateinoverloadresolution?我对以下C++11代码有两个问题:#includeusingnamespacestd;structA{A(){cout我用gcc和clang得到以下编译错误gcc-4.7.2(g++--std=c++11main.cpp):main.cpp:Infunction‘Af()’:main.cpp:16:9:error:useofdeletedfunction‘A::A(A&&)’main.cpp:8

c++ - "control reaches end of non-void function"枚举类型完全处理大小写切换

为什么即使处理了type_t的所有可能值,此代码也会触发“控制到达非空函数的结尾”?处理此警告的最佳方法是什么?在切换后添加return-1?(代码测试here)typedefenum{A,B}type_t;intuseType(type_tx){switch(x){caseA:return0;caseB:return1;}}相关:Detectingifcastinganinttoanenumresultsintoanon-enumeratedvalue 最佳答案 一般来说,enum不是唯一的。例如,有人可以像useType((ty

c++ - std::is_constructible on type with non-public destructor

std::is_constructible的预期结果是什么?在具有私有(private)或protected析构函数的类型上?例如,即使只有friend可以释放它,我仍然可以在堆上构造这样一个对象:#includeclassFoo{friendvoidfreeFoo(Foo*);public:Foo(){}private://Destructorisprivate!~Foo(){}};voidfreeFoo(Foo*f){deletef;//deletingafooisfineherebecauseoffriendship}intmain(){Foo*f=newFoo();//dele

windows - struct sockaddr,sin_family不是成员

根据msdn的这篇文章(http://msdn.microsoft.com/en-us/library/windows/desktop/ms740496(v=vs.85).aspx)结构因选择的协议(protocol)而异!现在我想使用http://www.intelliproject.net/articles/showArticle/index/check_tcp_udp_port中的这段代码检查端口是否打开!现在我有如下结构sockaddr:structsockaddr{ushortsa_family;charsa_data[14];};但需要这个结构:structsockaddr

java - Spring 安全 java.lang.IllegalArgumentException : Non-hex character in input

我在Windows7环境中的Tomcat服务器中部署了一个现有的Maven项目。我正在使用tomcat7,spring-security-core3.1.0。但是,每次我登录我的webapp时,我都会收到一个错误java.lang.IllegalArgumentException:Non-hexcharacterininput该代码在Linux环境中运行良好。所以我在想这是因为我在本地环境中使用的是windows7。当我查看互联网时,我发现这是linux和windows之间的编码问题。我试过设置JAVA_TOOL_OPTIONS-Dfile.encoding=UTF8但还没有成功。请帮

.net - 如何以编程方式检查 WCF Http/Non-Http 激活组件?

我需要检测在我的产品安装过程中是否安装了WCFHttp/Non-Http激活组件。我该怎么做?谢谢。 最佳答案 对于IIS7,检查以下注册表项:HKEY_LOCAL_MACHINE\Software\Microsoft\InetStp\Components\对于以下组件:流程模型-ProcessModel.NET环境-NetFxEnvironment配置API-WASConfigurationAPI从这个页面:http://learn.iis.net/page.aspx/135/discover-installed-componen