草庐IT

void_type

全部标签

c++ - 检查类 T 是否具有带有 void_t 的成员类型 Member

代码如下:templatestructhas_member_type:false_type{};templatestructhas_member_type>:true_type{};structfoo{usingbar=int;};intmain(){std::cout::value;}我正在尝试检查foo是否有bar类型的成员。如果实现不指定类型成员的名称,它工作正常,但这样名称被硬编码到实现中,这对我不起作用。据说重复的问题并不能回答我的问题。正如我在上面的段落中解释的那样,当类型被硬编码到实现中时它很好,但是当我从外部指定类型时我无法让它工作(这是特定问题)。代码编译正常,但产生

c++ - std::swap(*(void **)x, *(void **)y) 是什么意思?

我刚读了这个答案Howarevirtualfunctionsandvtableimplemented?.响应的作者使用了这个表达式:std::swap(*(void**)x,*(void**)y);//NowxisaC,andyisaB!Hopetheyusedthesamelayoutofmembers!有人可以解释一下它是如何工作的吗?为什么以及什么是(void**)后跟operator*? 最佳答案 它涉及未定义的行为,因此不能保证有效。基本思想是x和y是指向相同基类型对象的指针,其中该类型至少有一个虚函数,并且编译器通过在每

c++ - 循环依赖 : can't delete an incomplete type

我不明白为什么会出现此编译器错误:errorC2027:useofundefinedtype'GameState'note:seedeclarationof'GameState'errorC2338:can'tdeleteanincompletetypewarningC4150:deletionofpointertoincompletetype'GameState';nodestructorcalled这是相关代码:#pragmaonce#include#include"SpawnManager.h"#include"Resource.h"#include#includeclassGa

c++ - 将可变参数模板类型转换为 void,预期为 ')' 之前

在我的代码中,我使用可变参数模板函数作为日志记录机制。如果定义了DEBUG宏,则会打印一条消息;如果DEBUG未定义,那么它应该不打印任何内容。我的代码:#ifdefDEBUGinlinevoidLOG_CHAT(){}templatevoidLOG_CHAT(First&&first,Rest&&...rest){std::cout(first);LOG_CHAT(std::forward(rest)...);}#elsetemplatevoidLOG_CHAT(Rest&&...rest){(void)(rest...);}#endif我会将函数定义留空,但我不想得到“未使用的参数

c++ - 转发声明/包含在模板类中 - "invalid use of incomplete type"

我正在尝试制作一个模板类,其中有一个函数接受该模板的特定实例。我做了以下人为的例子来说明这一点。比方说,我有一个标有模板化(通用)数据类型的个人世界。我有一个特定的个体,称为国王。所有个人都应该能够在国王面前下跪。一般来说,个人可以被标记为任何东西。国王用数字标记(第1、2位国王)。错误g++-g-O2-Wall-Wno-sign-compare-Iinclude-DHAVE_CONFIG_H-c-oIndividual.oIndividual.cppg++-g-O2-Wall-Wno-sign-compare-Iinclude-DHAVE_CONFIG_H-c-oKing.oKing

c++ - "member of type foo has private copy constructor"错误 : why's it an error?

我试图定义这样一个类:#includeclassmy_class{private:someone_elsesfoo;public:myclass();~myclass();//...};但是编译器失败了:“someone_elses类型的字段foo有一个私有(private)的复制构造函数”。现在我知道我可以通过以下方式解决这个问题:classmy_class{private:someone_elses*foo;//...};my_class::my_class(){foo=newsomeone_elses();}my_class::~my_class(){deletefoo;}我的问

c++ - 将 const void* 指针转换为特定类指针

函数声明如下voidfunc1(constvoid&*pThis){MyClass*pMyClass=static_cast(pThis);//....IusePMyClasspointer.}我遇到错误无法将constvoid*转换为MyClass*这一步怎么做? 最佳答案 你可以MyClass*pMyClass=const_cast(static_cast(pThis));但这个糟糕的语法是一个提示:为什么函数有一个const参数,你不希望它像这样吗voidfunc1(void*pThis){当然,您可以使用C风格的转换来走捷径

c++ - 编译错误 : unresolved overloaded function type

我尝试用g++4.7.2编译以下内容:templatestructA{structB{Tt;templateTget(){returnthis->*M;}};Bb;Tget(){returnb.get();}};intmain(){Aa;a.get();}它给了我test.cpp:Inmemberfunction‘TA::get()’:test.cpp:15:23:error:expectedprimary-expressionbefore‘)’tokentest.cpp:Ininstantiationof‘TA::get()[withT=int]’:test.cpp:22:8:req

c++ - 错误 : aggregate 'first one' has incomplete type and cannot be defined

我写了这个头文件(header1.h):#ifndefHEADER1_H#defineHEADER1_Hclassfirst;//intsumm(inta,intb);#endif和这个源文件(header1.cpp和main.cpp):#include#include"header1.h"usingnamespacestd;classfirst{public:inta,b,c;intsum(inta,intb);};intfirst::sum(inta,intb){returna+b;}#include#include"header1.h"usingnamespacestd;firs

解决日期转换异常 JSON parse error: Cannot deserialize value of type `java.util.Date` from String总结

不积跬步,无以至千里;不积小流,无以成江海-----致奋斗的自己场景:前端向后端传日期参数,后端接收问题,在一次遇到这种低级问题总结一下。文档参考:​​​​​​​SpringFramework中文文档-SpringFramework4.3.21.RELEASEReference|Docs4devSpring是一个开放源代码的设计层面框架,它解决的是业务逻辑层和其他各层的松耦合问题,因此它将面向接口的编程思想贯穿整个系统应用。Spring是于2003年兴起的一个轻量级的Java开发框架,由RodJohnson创建。简单来说,Spring是一个分层的JavaSE/EEfull-stack(一站式)