草庐IT

unique-identifiers

全部标签

c++ - 用户创建的 header 导致 C2061 : Syntax Error : Identifier 'classname'

所以,我有点希望这最终会成为一个简单的答案,但我已经研究了一段时间,但似乎无法解决这个问题。所以我有一个特定的类,Intersection,当包含在任何其他header中时,它会给我:错误C2061:语法错误:标识符“Intersection”这是我的路口标题:#ifndefINTERSECTION_H#defineINTERSECTION_H#include"Coord.h"#include"Road.h"#include"TrafficLight.h"classIntersection{private:intid;Coord*midPoint;Road*northRoad;Road

c++ - 为什么 std::unique_ptr 不隐式转换为 T* 和 const T*?

如果我自己写,我想我会这样做:template>classUptr:privateDtor{T*vl_;public:explicitUptr(T*vl=nullptr)noexcept:vl_(vl){}~Uptr()noexcept{Dtor::operator()(vl_);}Uptr&swap(Uptr&o)noexcept{T*tmp;tmp=vl_;vl_=o.vl_;o.vl_=tmp;}Uptr&operator=(Uptr&&o)noexcept{o.swap(*this);}Uptr&operator=(nullptr_t)noexcept{vl_=nullptr;

c++ - 错误 C3861 : 'rollDice' : identifier not found

我正在尝试实现一些图形,但我在调用最底部显示的函数introllDice()时遇到问题,我不确定如何解决这个问题?任何想法...我收到错误错误C3861:“rollDice”:找不到标识符。introllDice();voidCMFCApplication11Dlg::OnBnClickedButton1(){enumStatus{CONTINUE,WON,LOST};intmyPoint;StatusgameStatus;srand((unsigned)time(NULL));intsumOfDice=rollDice();switch(sumOfDice){case7:case11

c++ - std::unique_ptr 作为在 std::thread 中运行的参数

这个问题在这里已经有了答案:visualstudioimplementationof"movesemantics"and"rvaluereference"(2个答案)关闭7年前。所以我试图将std::unique_ptr作为参数传递给在单独线程中启动的函数,并且我在编译时遇到了一个奇怪的错误:1>c:\programfiles(x86)\microsoftvisualstudio12.0\vc\include\functional(1149):errorC2280:'std::unique_ptr>::unique_ptr(conststd::unique_ptr>&)':attemp

c++ - std::unique_ptr 是基础对象的两倍大

我遇到了一个问题(特别是MSFTVS10.0的实现)std::unique_ptrs。当我创建它们的std::list时,我使用的内存是创建仅底层对象的std::list时的两倍(注意:这是一个大对象——~200字节,所以它不仅仅是一个周围有额外的引用计数器)。换句话说,如果我运行:std::listX;X.resize(1000,MyObj());我的应用程序需要的内存是我运行时的一半:std::list>X;for(inti=0;i(newMyObj()));我检查了MSFT的实现,但没有发现任何明显的问题——有人遇到过这个问题并有任何想法吗?编辑:好的,更清楚/具体一点。这显然是

c++ - 为什么 std::unique_ptr 没有 operator<<?

C++11标准中的[util.smartptr.shared.io]要求operator为了shared_ptr小号:templatebasic_ostream&operator&os,shared_ptrconst&p);然而,除非我遗漏了它,否则我在[unique.ptr]中看不到任何类似的东西,而且引用en.cppreference.com同意。有没有理由区别? 最佳答案 Isthereareasonforthedifference?不,没有。与make_unique一样,这是一个“疏忽”,应该在将来添加(如果有人愿意发送提案

c++ - std::unique_ptr<T[]> 和自定义分配器删除器

我正在尝试使用std::unique_ptr使用自定义内存分配器。基本上,我有自定义分配器,它们是IAllocator的子类,它提供了以下方法:void*Alloc(size_tsize)templateT*AllocArray(size_tcount)voidFree(void*mem)templatevoidFreeArray(T*arr,size_tcount)由于底层内存可能来自预分配block,因此我需要特殊的...Array()-分配和释放数组的方法,它们分配/释放内存并调用T()/~T()在范围内的每个元素上。现在,据我所知,std::unique_ptr的自定义删除器|

c++ - `std::vector< std::unique_ptr< T >>` 错误

我看到一些错误传递std::vector>周围有std::move.重现问题的代码是这样的:#include//forstd::unique_ptr#include//forstd::move#include//forstd::vectorstructbar{};usingvtype=std::vector>;structfoo{foo(vtypev):_v(std::move(v)){}private:vtype_v;};vtypegetVector(){return{std::move(std::unique_ptr(newbar()))};};intmain(){foof(std

c++ - 在 vector 声明中移动 unique_ptr

这个问题在这里已经有了答案:CanIlist-initializeavectorofmove-onlytype?(8个答案)关闭5年前。我尝试在vector声明期间移动一些unique_ptr,但出现错误。我认为我在不知情的情况下进行了复制。我不明白为什么我在声明时遇到问题,而它在push_back期间工作得很好。我用几行简化了问题。#include#include#includeusingnamespacestd;intmain(){unique_ptri1=make_unique(142);unique_ptri2=make_unique(242);unique_ptri3=mak

c++ - 在 for range 循环中迭代包含 vector 的取消引用的 unique_ptr

为什么这段代码不像我想象的那样工作?for(autoit:*std::make_unique>(std::vector({1,2,3,4,5})))std::coutvector对象在执行循环的第一次迭代之前被销毁 最佳答案 range-basedforloop相当于:{init-statementauto&&__range=range_expression;...}对于您的range_expression,它将是auto&&__range=*std::make_unique>(std::vector({1,2,3,4,5}));但