草庐IT

deleter_type

全部标签

C++ : Different deduction of type auto between const int * and cont int &

这里是代码示例。a.intii=0;b.constintci=ii;c.autoe=&ci;-->eisconstint*d.auto&f=42;-->invalidinitializationofnon-constreferenceoftype‘int&’fromanrvalueoftype‘int’e.constauto&g=42-->ok观察:1.对于c)子句,自动推导类型const2.对于子句d),不会自动推导出类型const3.对于条款e),必须手动添加类型const才能使其工作。为什么子句c而不是d会自动推导类型const? 最佳答案

c++ - 为什么这个无锁堆栈类中的 'deleting' 节点会导致竞争条件?

在AnthonyWilliams的《C++ConcurrencyinAction》一书中,第7.2.1节列出了一个无锁堆栈实现:templateclasslock_free_stack{structnode{shared_ptrdata_;node*next_;node(constT&data):data_(make_shared(data)){}};atomichead_;public:voidpush(constT&data){node*new_node=newnode(data);new_node->next_=head_.load();while(!head.compare_e

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++ - 是否需要将 delete 用于在 vector 中创建的新数组?

我正在尝试为void**数据数组创建一些动态数组。std::vectordata;data.push_back(newdouble[1024]);//arrayofdoublesdata.push_back(newshort[1024]);//arrayofshorts为了清理我应该只使用data.clear();或者是否需要删除每个新的(s),如果需要,如何完成? 最佳答案 ForcleanupshouldIjustusedata.clear();这将从vector中删除所有指针。如果其中任何一个是指向它们各自动态对象的唯一拷贝,

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++ - 如果我有运算符 T *(),是否需要重载 delete?

如果我有一个包含指针的模板类A,并且A有一个将返回该指针的隐式转换运算符,我是否需要,或者我应该,为A定义一个delete运算符,如果我打算将delete应用于此类的对象? 最佳答案 如果定义operatornew,则只需定义operatordelete——在这种情况下,您几乎必须这样做。这并不意味着某些东西不需要删除您的A*——但您不需要为此定义任何运算符,它会默认工作。 关于c++-如果我有运算符T*(),是否需要重载delete?,我们在StackOverflow上找到一个类似的问

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++ - 编译错误 : 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(一站式)