草庐IT

has_public_member_foo

全部标签

c++ - 如何将 unique_ptr 移出 vector<unique_ptr<Foo>>?

我想搬一个unique_ptr从一个vector>.考虑我的代码:#include#include#includeusingnamespacestd;classFoo{public:intx;Foo(intx):x(x){};~Foo(){cout>();foos.push_back(unique_ptr(newFoo(100)));foos.push_back(unique_ptr(newFoo(101)));foos.push_back(unique_ptr(newFoo(102)));//Printallcoutxxx我预计它会产生:Vectorsize:3100101102Re

c++ - 在公共(public)接口(interface)中使用共享指针

我们有一个使用共享指针的非常标准的树API,大致如下所示(为简洁起见省略了实现):classnode;usingnode_ptr=std::shared_ptr;classnode:publicstd::enable_shared_from_this{std::weak_ptrparent;std::vectorchildren;public:virtual~node()=default;virtualvoiddo_something()=0;voidadd_child(node_ptrnew_child);voidremove_child(node_ptrchild);node_pt

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++ - Q_INVOKABLE 是否需要在 Qt5 中从 QML 调用公共(public) QObject 函数?

我刚刚意识到我几乎可以调用公开给QML的对象的任何函数。现在我对Q_INVOKABLE很好奇。Qt5docs状态:[...]anyQMLcodecanaccessthefollowingmembersofaninstanceofaQObject-derivedclass:PropertiesMethods(providingtheyarepublicslotsorflaggedwithQ_INVOKABLE)SignalsSinceQt5(在C++中)我可以像槽一样调用QObject的任何公共(public)函数,即我不必将它们声明为“公共(public)槽”。这是否意味着我可以从QM

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++ -/boost/lockfree/queue.hpp: 错误: 静态断言失败: (boost::has_trivial_destructor<T>::value)

我正在尝试替换boost::lockfree::queue对于std::queue在这个文件中https://github.com/zaphoyd/websocketpp/blob/experimental/examples/broadcast_server/broadcast_server.cpp我添加了#include;改线130,std::queuem_actions;,至boost::lockfree::queuem_actions;;删除所有与锁定有关的行;并更改了行103,m_actions.pop();,至m_actions.pop(a);.我在sconsbroadcas

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

c++ - C++中虚拟公共(public)类的副作用

VirtualPublicClass用于一个类,保证一个类的一个对象只继承一个子对象。classL{/*...*/};//indirectbaseclassclassB1:virtualpublicL{/*...*/};classB2:virtualpublicL{/*...*/};classD:publicB1,publicB2{/*...*/};//valid当我们不将它用于单继承时,我们使用virtualpublic时会产生副作用吗?例如,是classL{/*...*/};//indirectbaseclassclassB1:virtualpublicL{/*...*/};cla

c++ - vector<shared_ptr<Foo>> 到 vector<shared_ptr<const Foo>> 的隐式转换

根据thispage您可以隐式转换shared_ptr至shared_ptr.这很有道理。但是,当我尝试转换std::vector时遇到错误包含shared_ptr到一个包含shared_ptr的.有没有什么好的方法可以实现这种转化? 最佳答案 编号:std::vector>和std::vector>是不同的类型,因此您不能将一种类型的对象视为另一种类型的对象。如果你真的需要std::vector>,你可以很容易地用shared_ptr创建一个s到与原始元素相同的元素:std::vector>v;std::vector>cv(v.b

c++ - 这个 has_member 类模板是如何工作的?

我试图了解以下类模板的工作原理(取自here),但我无法正确理解它:templateclasshas_member{classyes{charm;};classno{yesm[2];};structBaseMixin{voidoperator()(){}};structBase:publicType,publicBaseMixin{};templateclassHelper{};templatestaticnodeduce(U*,Helper*=0);staticyesdeduce(...);public:staticconstboolresult=sizeof(yes)==sizeo