草庐IT

protected_class_method

全部标签

c++ - 是否有可能调用一个父类(super class)的构造函数,两个类远离 C++ 中的当前类

我有三个继承如下的类:Class_AClass_B:publicClass_AClass_C:publicClass_BClass_A包含一个构造函数:public:Class_A(constchar*name,intkind);Class_B不包含该构造函数。在Class_C中,我希望调用Class_A的构造函数。像这样的东西:Class_C(constchar*name,intkind):Class_A::Class_A(name,kind){}问题是我无法向Class_B添加中间构造函数,因为Class_B是生成的代码,每次我makeclean时都会重新生成。所以我无法对Clas

c++ - 前向声明的类型和 "non-class type as already been declared as a class type"

我对以下代码有疑问:templatevoidfoo(structbar&b);structbar{};intmain(){}它在GCC上编译成功,但在MSVC(2008)上编译失败并出现以下错误:C2990:“bar”:已声明为类类型的非类类型是代码错误还是MSVC中的错误?如果我在模板定义之前添加structbar;就可以了。 最佳答案 我们有我们的赢家:https://connect.microsoft.com/VisualStudio/feedback/details/668430/forward-declared-type-

c++ - 标准 :forward inside a template class

templateclassBlockingQueue{std::queuecontainer_;templatevoidpush(U&&value){static_assert(std::is_same::type>::value,"Can'tcallpushwithoutthesameparameterastemplateparameter'sclass");container_.push(std::forward(value));}};我希望BlockingQueue::push方法能够处理T类型对象的右值和左值引用,以将其转发到std::queue::push正确的版本。是像上面

c++ - 错误 : ‘template<class> class std::auto_ptr’ is deprecated

我正在使用scons和ubuntu。当我使用'scons'制作一些程序时,会发生错误,例如,src/db/DBTextLoader.cc:296:3:error:‘templateclassstd::auto_ptr’isdeprecated[-Werror=deprecated-declarations]/usr/include/c++/5/bits/unique_ptr.h:49:28:note:declaredheretemplateclassauto_ptr;这是我的命令;$./configuer$sourcesomething.sh$scons其实我也不知道。我已经在搜索这个

c++ - 对于类型 Class::Type,我可以从 const Class 派生 const Class::Type 吗?

我正在实现一个容器,例如:templateclassContainer{public:usingvalue_type=T;...};是否有从constContainer派生constvalue_type的好方法?背景:我已经通过嵌套模板类实现了迭代器类型:templateclassiterator_base{public:...Value&operator*()const;private:Container*c;};usingiterator=iterator_base;usingconst_iterator=iterator_base;工作正常,但iterator_base的第二个模

c++ - boost::bind protected 成员和上下文

在下面的代码中,有两个使用boost:bind表达式对std::for_each的“等效”调用。指示的行编译,指示的失败行失败。我能在标准中找到的最佳解释是“因为我们这么说”。我正在寻找“为什么标准表明这种行为”。我的假设如下。我的问题很简单:为什么指定的行可以编译而下面的等效行无法编译(我不想因为“标准是这样说的”,我已经知道了-我不会接受任何给出的答案这是一个解释;我想要一个关于为什么标准这样说的解释)。注:虽然我用的是boost,但是boost与本题无关,使用g++4.1.*和VC7.1复现了各种格式的错误。#include#include#include#includeclas

c++ - Eigen 错误 : please_protect_your_min_with_parentheses

我正在尝试通过运行包附带的测试代码来测试Eigen的非线性优化功能。我被这些错误困住了(更像是困惑):Error5errorC2039:'please_protect_your_min_with_parentheses':isnotamemberof'std::numeric_limits'c:\programfiles(x86)\microsoftsdks\windows\v7.0a\include\eigen-eigen-5097c01bcdc4\unsupported\eigen\src\nonlinearoptimization\lmpar.h184Error7errorC20

c++ - 不完整类型 struct std::hash 与 unordered_map 的无效使用,其中 std::pair of enum class 作为键

我想使用unordered_map,std::uint8_t>用于管理一些像素图格式。这里是最少的代码:#include#include#include#include#includeenumclassPNM:std::uint8_t{PBM,PGM,PPM};enumclassFormat:bool{BIN,ASCII};structpair_hash{public:templatestd::size_toperator()(conststd::pair&x)const{returnstd::hash()(x.first)^std::hash()(x.second);}};intma

c++ - 在派生类中强制执行 protected 构造函数

是否有任何机制允许在派生类中强制执行protected构造函数?简单的例子:templateclassFactory;classBase{templatefriendclassFactory;protected:Base();};classChild:publicBase{public:Child();//thisshouldleadtoacompiletimeerror};classFactory{Base*GetNew(){BOOST_STATIC_ASSERT(boost::is_base_of::value);Base*b=newT();b->doStuff();returnb

c++ - 指向具有 protected 继承的基类方法的指针

我有这个代码:classFoo{public:intx=4;int&operator[](size_tindex){returnx;}};classBar:protectedFoo{public:usingFoo::operator[];Bar(){x++;}};intmain(intagrc,char**argv){typedefint&(Bar::*getOp)(size_tindex);Barb;autobVal=b[4];getOpo=&Bar::operator[];autobVal2=(b.*o)(7);}但是,我不能编译它,因为errorC2247:'Foo'notacc