【发布时间】:2014-06-20 16:40:05
【问题描述】:
例如,我有一个包含许多方法的基类
class A
{
public:
void f1();
int f2() const;
float f3(double a, char b) const;
...
};
而一个类B是从A私有派生的。我想让A的一些方法是公开的,怎么办?
class B : private A
{
public:
using A::f1;
using A::f2;
template<class... Args>
RETURN f3(Args&&... args) CONSTNESS { return A::f3(args...); }
// how to specify return and constness automatically
...
};
我尝试了上述方法,但它们不起作用。模板方式需要自动指定return和constness。
问错了,在我的真实案例中,A是一个模板类
template<class T>
class A
{
public:
void f1();
int f2() const;
float f3(double a, char b) const;
...
};
B 派生自 A
template<class T>
class B : public A
{
public:
using A::f1; // wrong
using A<T>::f1; // okay
};
【问题讨论】:
-
using A::f1应该可以工作。你用什么编译器?
标签: c++ templates inheritance c++11