通常,我们希望使用私有继承来将实现细节隐藏到基类中。如果是这样, 1)为什么名称公布功能又出现了?仅仅是为了语言的完整性还是有实际用法呢? 2)即使我公开基类函数名,派生类仍然可以声明具有相同名称的另一个函数。请考虑下面的代码。 #include "iostream"
using namespace std;
class Base {
public:
int zoo;
,请参见下面的代码 struct A { using type = int; };
struct B : private A {};
struct C : B { using base_type = A; };
所有GCC 6.1,铛3.8和MSVC 2015年更新3拒绝编译这一点,因为A是不是因为里面C的访问名称A是B的私人基础。看来gcc认为A在using base_type = A是
让我们考虑两个类A和B具有以下接口: class A {
public:
virtual void start() {} //default implementation does nothing
};
class B {
public:
void start() {/*do some stuff*/}
};
,然后第三类来自继承,A公开,因为它实现了这个“接口
在私有继承的基类对象和子对象之间有以下三种类型转换,其中两种工作,但最后一种不支持。我想知道是什么导致了不同的结果。 #include<iostream>
#include <string>
using namespace std;
class test :private string
{
public:
test(string st) :string(st){}
v