草庐IT

member-hiding

全部标签

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++ - "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++ - 这个 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

c++ - caffe 安装 : gcc error namespace "std" has no member "isnan"

我正在尝试安装(py)caffe在ubuntu17.10上然而,当我执行makeall时,出现以下错误:./include/caffe/common.hpp(84):error:namespace"std"hasnomember"isnan"./include/caffe/common.hpp(85):error:namespace"std"hasnomember"isinf"2errorsdetectedinthecompilationof"/tmp/tmpxft_00004921_00000000-19_nesterov_solver.compute_61.cpp1.ii".Mak

C++继承设计: avoid member duplication

假设有两个C++类,分别支持对文件描述符的只读和只写操作。classReadFd{public:ssize_tread(/**/){//readfromfile_descriptor_}protected:intfile_descriptor_;};classWriteFd{public:ssize_twrite(/**/){//writetofile_descriptor_}protected:intfile_descriptor_;};现在假设要定义一个类ReadWriteFd,它支持读写操作。我的问题是如何设计这样的读写类来避免代码重复?我不能同时继承ReadFd和WriteFd

c++ - 嵌入式 C++ : Initialization of an array member of a struct within a class, 大小省略

您好,在此先感谢您对以下问题的任何帮助。编辑:我忘了补充一点,这是在无法访问STL功能的嵌入式系统上。我很抱歉遗漏了这条非常重要的信息。这是我第一次广泛使用C++进行编码,所以我忘了提及显而易见的事情。我回来补充这个事实,这个问题已经收到了一些回复。感谢大家这么快的回复!我正在尝试初始化结构的数组成员,该结构又是C++类的公共(public)成员。结构中省略了数组大小。这是一个例子://ClassA.hClassA{public:structStructA{StructBstructs[];};structStructB{//stuff};ClassA();//etc};//Class

c++ - 从结构中调用 Pointer-to-Member-Function 指向的函数

我有一个具有特殊数据结构的类Test。Test类的成员是std::map,其中键是std::string,映射值是struct定义如下:typedefstruct{void(Test::*f)(void)const;}pmf_t;map初始化正常。问题是当我试图调用指向的函数时。我编了一个重现问题的玩具示例。在这里:#include#includeusingnamespacestd;classTest;typedefvoid(Test::*F)(void)const;typedefstruct{Ff;}pmf_t;classTest{public:Test(){pmf_tpmf={&T

c++ - "Provides no initializer for reference member..."

经过一些谷歌搜索后,我找不到这个问题的答案。如何初始化它,为什么需要初始化?#include"CalculatorController.h"CalculatorController::CalculatorController(SimpleCalculator&aModel,ICalculatorView&aView){\\(thisisthebracketinformingmeoftheerror)fModel=aModel;fView=aView;}标题:#pragmaonce#include"ICalculatorView.h"#include"SimpleCalculator.h

c++ - 如何使用内联函数说明符将 "hide"私有(private)成员函数?

有一个包含private成员函数的类,我想标记为inline(明确标记我的意图,即特定函数可能被内联),但不要将它们的实现暴露给API使用者。为简单起见,它可能看起来像:飞机.h:classAirplane{charmanufacturer[80];charmode[80];//...public:voidautopilot_steer_left(intdegree);//...private://...inlineboolvalidate_hydraulic_on_left_wing();//secret,patent-based,etc.};飞机.cpp:#include"Airp

c++ - 在继承 : Can I override base class data members?

假设我有如下两个类:ClassA{public:..private:intlength;}ClassB:publicClassA{public:..private:floatlength;}我想知道的是:是否允许覆盖基类数据成员?如果是,这是一种好的做法吗?如果不是,扩展类数据成员类型的最佳方法是什么?有一个类满足了我的需求,我想重用它。但是为了我的程序需要,它的数据成员应该是另一种类型。我有一些书,但它们都只涉及重写基类成员方法。 最佳答案 您可以使用模板化成员,即通用成员,而不是覆盖成员。您还可以声明一个类似union的VARI