草庐IT

forward-declaration

全部标签

c++ - 枚举 [标签] [ : type] {enum-list} [declarator] in C++ - is this legal?

我正在使用C++中的自定义枚举类型,但它没有很多值。我想尝试减小它们占用的大小,而且我听说enum类型是alwaysintegersbydefault.然后我遇到了MSDNentryonC++enumerations,发现下面的语法很有趣:enum[:type]{enum-list};果然,当我执行以下操作时,它编译出了我想要的(VS2008):enumplane:unsignedchar{xy,xz,yz};现在,您可以从我的枚举常量中看出我不需要太多空间-unsignedchar类型非常适合我的使用。但是,我不得不说,我从未在互联网上的其他地方任何地方见过这种形式——大多数人甚至似

c++ - 带有参数 std::unique_ptr<T>&& 的 std::move 或 std::forward

我有以下模板类(精简后只包含相关部分)和一个名为Push的方法用C++11编写:templateclassCircularStack{private:std::array,Capacity>_stack;public:voidPush(std::unique_ptr&&value){//somecodeomittedthatupdatesan_indexmembervariable_stack[_index]=std::move(value);}}我的问题是:ShouldIbeusingstd::moveorstd::forwardwithinPush?我不确定std::unique_

c++ - "error: ’ myfn' declared as function returning a function"是什么意思?

我正在尝试编写一个返回函数指针的函数。这是我的最小示例:void(*myfn)(int)()//Doesn'twork:supposedtobeafunctioncalledmyfn{//thatreturnsapointertoafunctionreturningvoid}//andtakinganintargument.当我用g++myfn.cpp编译它时,它打印出这个错误:myfn.cpp:1:19:error:‘myfn’declaredasfunctionreturningafunctionmyfn.cpp:1:19:warning:extendedinitializerli

c++ - 如何以及何时使用 Q_DECLARE_METATYPE

我需要在整个项目中将QSqlRecord转换为QVariant并返回。为此,我添加了Q_DECLARE_METATYPE(QSqlRecord);在需要转换的类的.h文件中。我还有一个基类,几个child从中继承,在这种情况下,我假设在基类中只包含一次Q_DECLARE_METATYPE就足够了。因此,我有例如:widgetBaseClass:声明元类型widgetChildClass1:继承widgetBaseClass,不声明元类型widgetChildClass2:继承widgetBaseClass,不声明元类型myTableModel:声明元类型当我尝试像这样运行程序时,我得到

c++ - 带有容器和默认分配器的模板模板参数 : can I make my declaration more compact?

我在看这个有趣的话题:https://stackoverflow.com/a/16596463/2436175我的具体案例涉及使用来自opencv的cv::Point_和cv::Rect_的标准容器声明模板函数。我想针对以下模板:我将使用的标准容器类型完成cv::Point_和cv::Rect_定义的基本数据类型我最终做出了以下声明:templateclassContainer_t>voidCreateRects(constContainer_t,std::allocator>>&points,constTvalue,Container_t,std::allocator>>&rects

c++ - std::forward 和带有非常量引用参数的构造函数

在右值引用简介中,提出了完美转发作为将右值5转发到具有非常量引用参数的构造函数的理想解决方案。但是:#include#include#includetemplatestd::shared_ptrfactory(A1&&a1){returnstd::shared_ptr(newT(std::forward(a1)));}classX{public:X(int&i){std::coutp=factory(5);}在XCode4.2和G++4.6.1中失败,没有已知的从int到int&的转换,而:templatestd::shared_ptrfactory(A1&&a1){returnstd

c++ - 如何 'hide' 虚假 "declared but never used"警告?

我正在使用Borland(又名“Embarcodegearland”)C++Builder2007编译器,它有一个小错误,系统头文件中的某些staticconst项可能导致虚假的"xyzzy已声明但从未使用过”警告。我正试图让我的代码100%没有警告,所以想要一种屏蔽这些特定警告的方法(注意-但不是简单地关闭警告!)此外,我无法修改头文件。我需要一种“伪造”元素用途的方法,最好甚至不知道它们的类型。例如,将此函数添加到我的.cpp模块可修复这四个项目的警告,但它似乎有点“临时”。有没有更好的、最好是self记录的方式来做到这一点?staticintfakeUse(){returnOne

c++ - std::forward vs std::move 同时将左值绑定(bind)到右值引用

这里move和forward有区别吗:voidtest(int&&val){val=4;}voidmain(){intnb;test(std::forward(nb));test(std::move(nb));std::cin.ignore();} 最佳答案 在您的具体情况下,不,没有任何区别。详细答案:在幕后,std::move(t)做static_cast::type&&>(t),其中T是t的类型(参见§20.2.3/6)。在您的情况下,它解析为static_cast(nb).forward有点棘手,因为它是为在模板中使用而量身

C++ block scope extern declaration linkage,混淆C++标准解释

标准N3242(C++11草案)和N3797(C++14draft)两者有相同的段落。§3.5Programandlinkage[basic.link]¶6Thenameofafunctiondeclaredinblockscopeandthenameofavariabledeclaredbyablockscopeexterndeclarationhavelinkage.Ifthereisavisibledeclarationofanentitywithlinkagehavingthesamenameandtype,ignoringentitiesdeclaredoutsidethei

c++ - 使用 bind2nd() : "member function already defined or declared" instead of "reference to reference" 的奇怪编译器错误

我最近花了很多时间来理解在这段代码中调用func()时的错误消息:intmain(){vector>v;doublesum=0;for_each(v.begin(),v.end(),bind2nd(ptr_fun(func),&sum));return0;}当func()像这样声明时,代码编译正常:voidfunc(vectorv,double*sum){}当我使用这个声明(为了提高效率)时,我得到了一个编译器错误:voidfunc(constvector&v,double*sum){}我期望看到的错误类似于reference-to-reference错误,因为binder2nd的op