【发布时间】:2014-05-25 22:08:54
【问题描述】:
我无法在一个小样本中隔离此错误以在此处进行演示,但即使错误消息是如此自相矛盾,以至于人们无需测试即可知道这是否是错误。
我有一个结构(可能是公开的)派生另一个结构,但 clang 坚持认为这是隐含的私有继承:
error: 'next' is a private member of 'base'
note: constrained by implicitly private inheritance here
struct derived_temp <key> : base <derived>
虽然 g++ 编译得很好。我只更改了类的实际名称以使消息更具可读性。代码如下所示:
template </*...*/>
struct base : //...
{
private:
//...
public:
template <typename I> I next(I i) const { return /*...*/; }
//...
};
template <typename /*...*/>
struct derived_temp;
struct key { /*...*/ };
using derived = derived_temp <key>;
template <>
struct derived_temp <key> : base <derived>
{
//...
};
我试图保持代码的形式与我的项目中的完全相同,只是更改了名称并注释掉了其中的一部分。
该错误是由于尝试在 derived 类型的临时对象上调用函数 next() 引起的。
我唯一的解释是,这可能是 clang 的一个错误(但是,我无法在小样本中重现它)迫使我改变
struct derived_temp <key> : base <derived>
更明确
struct derived_temp <key> : public base <derived>
有什么想法吗?
【问题讨论】:
-
在不知道您的
...省略号的至少一部分的情况下,我们无法冒险猜测...如果您跳过using并尝试struct derived_temp<key>: base<derived_temp<key>>会发生什么?base的参数是什么?它继承自什么? -
@Massa 我明白了,但是半小时后我仍然无法找出问题,所以我决定只添加
public关键字而不是继续搜索 :-) -
@Massa 如果跳过
using,没有任何变化。base将单个参数传递给派生类,例如D,它继承自同样以D为模板的实用程序类,该类提供重载方法der()以方便地将对象转换为D&&、@987654338 @,或const D&。就是这样。 -
忘了问:哪个版本的clang?
-
@Massa clang 3.3。不幸的是,我还没有 3.4。
标签: c++ inheritance struct public