草庐IT

unique_no

全部标签

c++ - unique_ptr refcount 的替代方案

在下面的代码示例中,只要B的任何对象存在,就应该在structB中存在一个structA的实例.示例按预期工作。#include#include#includestructA{A(){std::coutguard(mtx);if(!refCount){a.reset(newA);}++refCount;}~B(){std::coutguard(mtx);--refCount;if(!refCount){a.reset();}}staticstd::unique_ptra;staticstd::mutexmtx;staticintrefCount;};std::unique_ptrB::

C++ 模板和 "no matching function to call"

我遇到了一个奇怪的错误。我有以下签名的功能:templatestaticboolConvertCbYCrYToRGB(constCharacteristicspace,constDATA*input,DATA*output,constintpixels){后来这样称呼:casekByte:returnConvertCbYCrYToRGB(space,(constU8*)input,(U8*)output,pixels);casekWord:returnConvertCbYCrYToRGB(space,(constU16*)input,(U16*)output,pixels);casek

c++ - 示例 XSD 失败并返回 "error: no declaration found for element X"

尽管我是xml解析领域的新手,但我能够通过xsd创建有效的c++并成功编译和链接,但是编译器优化了(?)离开实例化。所以,从第一步开始,我尝试helloworldxmlexampleatCodeSynthesis.但这失败了:[wally@lenovotowerxml]$makehelloxsdcxxcxx-treehello.xsdg++-c-ohelloschema.ohello.cxxg++-g-ohello-lxerces-chelloschema.ohello.c++[wally@lenovotowerxml]$./hellohello.xml:2:8error:nodecl

C++ 编译错误 - 命名空间 std 中的 "no type named ' 函数”

我正在为我的C++编程类(class)作业,其中涉及实现HashMap。我的导师给了我们一个头文件,我们需要将其与我们的HashMap类一起使用。提供的头文件包含以下行:typedefstd::functionHashFunction;根据我对C++的(有限的)理解,这会将HashFunction类型定义为std::function。但是,当我编译代码时,出现错误:./HashMap.h:46:15:error:notypenamed'function'innamespace'std'typedefstd::functionHashFunction;~~~~~^./HashMap.h:

c++ - boost std unique_ptr 的 STL 集合的序列化

我希望能够序列化std::unique_ptr的STL容器。可以吗?顺便说一句,单个std::unique_ptr一切正常。下面是我正在处理的代码,gcc给出了以下错误:useofdeletedfunction‘std::unique_ptr::unique_ptr(conststd::unique_ptr&)[with_Tp=MyDegrees;_Dp=std::default_delete;std::unique_ptr=std::unique_ptr]’如何使代码正常工作?#include#include#include#include#include#include#inclu

已解决module ‘keras.preprocessing.image‘ has no attribute ‘load_img‘异常的正确解决方法,亲测有效!!!

已解决module‘keras.preprocessing.image‘hasnoattribute‘load_img‘异常的正确解决方法,亲测有效!!!文章目录问题分析报错原因解决思路解决方法总结在深度学习项目中,图像预处理是一个重要步骤。TensorFlow的KerasAPI提供了丰富的图像预处理功能,其中load_img函数用于加载图像是非常常用的一个功能。然而,在使用时可能会遇到AttributeError:module'keras.preprocessing.image'hasnoattribute'load_img'的错误信息。本篇文章将详细解析这个问题的原因,并提供亲测有效的解决

c++ - 制作 : No rule to make a header file?

我正在尝试使用名为BigInt的库创建一个项目。我的文件结构是:/Users/wen/Projects/challenge/fibonacci3/fibonacci3.cpp/Users/wen/Projects/challenge/fibonacci3/Makefile/Users/wen/Projects/include/bigint//Users/wen/Projects/include/bigint/MakefileFibonacci3Makefile截至LD_FLAGS=CC_FLAGS=#Includelibrariesinclude/Users/wen/Projects/

c++ - boost::ptr_vector 对比 std::vector<std::unique_ptr<T>>?

按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visitthehelpcenter指导。关闭9年前。他们做类似的事情。在两者之间进行选择时应该考虑什么?在哪种情况下,哪一个是首选?

c++ - 拥有一个具有原始指针访问器的 unique_ptr 成员是不好的做法吗?

我有一个类有一个unique_ptr成员,并且这个类保留这个对象的唯一所有权。但是,外部类可能需要访问此对象。在这种情况下,我应该只返回一个原始指针吗?shared_ptr似乎不正确,因为这意味着访问类现在共享该内存的所有权,而我想明确指出原始类是唯一所有者。例如,也许我有一个拥有根节点的树类。另一个类可能出于某种原因希望探索树,并且需要指向根节点的指针来执行此操作。部分实现可能如下所示:classTree{public:Node*GetRoot(){returnm_root.Get();}private:std::unique_ptrm_root;};这是不好的做法吗?更好的解决方案

c++ - 错误 : no instance of overloaded function "std::make_shared" matches the argument list

查看ApreviousstackQuestionstd:make_sharedvsstd::shared_ptr,我试图在一个uni项目中实现它。这是之前的“问题”:Ican'tthinkofanysituationwherestd::shared_ptrobj(newObject("foo",1));wouldbepreferredtoautoobj=std::make_shared("foo",1);因此我采用了这段代码:std::shared_ptrpT1(newTriangle(pCanvas,30,30,30,60,60,30,255,0,0));并将其修改为这段代码:aut