草庐IT

c++ - C++模板成员指针属性实现的一些问题

我的目标是像在C#中一样在C++中创建属性-具有重要的设置/获取行为。在这里,Property的对象包含对prop及其set/get方法的master的引用。Property.h的实现、内容:#includeusingnamespacestd;namespaceFirst{templatestructProperty{Master&master;constType(Master::*&get)()const;Type(Master::*&set)(Typevalue);Property(Master&master,constType(Master::*get)()const,Type(

c++ - result_of 对我不起作用

#includeusingnamespacestd;structasd{voidf();};intf();typedeftypenameresult_of::typeresult_free;typedeftypenameresult_of::typeresult_mem;两个typedef都报错Infileincludedfrom../main.cpp:1:0:/usr/include/c++/4.6/type_traits:Ininstantiationof‘std::_Result_of_impl’:/usr/include/c++/4.6/type_traits:1215:12:

c++ - type_info 不考虑 cv 限定符 : is this right?

这段代码打印1是正确的行为还是g++4.5的怪癖?#include#includeusingnamespacestd;intmain(){structA{};cout我认为cv限定符的不同类型作为非常不同的类型受到威胁,即使较少的cv限定类型可以隐式转换为更多cv限定的类型。 最佳答案 typeid根据C++标准(摘自ISO/IEC14882:2003的§5.2.8)忽略cv限定符:Thetop-levelcv-qualifiersofthelvalueexpressionorthetype-idthatistheoperandof

c++ - Variadic 模板和 "expected a type"错误

我正在(主要是出于学习目的)自己实现tuple,我刚刚遇到了一个问题。我有以下代码:namespaceRose{templatestructRemoveReference{typedefTType;};templatestructRemoveReference{typedefTType;};templateclassTuple;templateclassTuple{public:Tuple(Firsta,Elems...more):More(more...),Element(a){}Tuple&operator=(constTuple::Type,RemoveReference::Ty

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++ - 通用模板非类型参数

我希望我的类接收一个非类型模板参数,但我不想指定非类型参数的类型。我可以这样写:templateclassA{};然后可以按如下方式使用:Aa;这是多余的,因为一旦我知道param=3,那么我就知道Type=int。有没有什么方法可以这样写,以便以下所有行都可以编译和实例化不同的类型?Aa;Ab;Ac; 最佳答案 不,那是不可能的。所有非类型模板参数的类型都必须在参数中定义,并且永远不能从使用中推断出来,即当编译器分析时,您需要Type已知参数Typeparam。 关于c++-通用模板非

c++ - 匹配可迭代类型(具有 begin()/end() 的数组和类)

这个问题在这里已经有了答案:Checkifavariabletypeisiterable?(6个答案)关闭9个月前。我写了类型特征,比如可以用来测试给定类型是否“可迭代”的类。对于数组(对于T[N],而不是对于T[])和具有begin和的类来说都是如此>end方法返回看起来像迭代器的东西。我想知道是否可以做得比我做的更简洁/更简单?特别是impl命名空间中的东西看起来有点迂回/hacky。这一切在我看来都有点难看。有关使用它并可以用g++和clang++编译的示例,请参见:https://gist.github.com/panzi/869728c9879dcd4fffa8templat

c++ - 使用 vector<int>::size_type 和普通整数有什么区别?

我是c++STL语言的初学者。我想知道这两个代码之间的区别。我问过我的friend,但他说两者是一样的。任何人都可以解释这两个是否相同。并解释为什么这些不同#include#includeusingnamespacestd;intmain(){vectorstudent_marks(20);for(vector::size_typei=0;i>student_marks[i];}return0;}和#include#includeusingnamespacestd;intmain(){vectorstudent_marks(20);for(inti=0;i>student_marks[

c++ - 错误 : cannot declare variable ‘bg’ to be of abstract type ‘cv::BackgroundSubtractorMOG2’ in OpenCV 3

我最近在我的ubuntu14.10系统中安装了OpenCv并且我正在运行一个程序并且正在运行cv::BackgroundSubtractorMOG2我遇到了一个错误。错误是cannotdeclarevariable‘bg’tobeofabstracttype‘cv::BackgroundSubtractorMOG2’为什么我会遇到这个错误我的代码示例intmain(intargc,char*argv[]){Matframe;Matback;Matfront;vector>hand_middle;VideoCapturecap(0);BackgroundSubtractorMOG2bg;

c++ - 有没有比 allocator_type 更好的方法来区分可调整大小的容器?

我有operator>>()的模板重载,我需要区分可以调整大小的容器(例如vector)和不能调整大小的容器(例如,数组。我目前只是在使用allocator_type特征(见下面的代码)——它工作得很好——但想知道是否有更明确的测试方法。templatestructis_resizable{typedefuint8_tyes;typedefuint16_tno;templatestaticyestest(classU::allocator_type*);templatestaticnotest(...);staticconstboolvalue=sizeoftest(0)==sizeo