我一直在从g ++声称一个类型别名是私人的非常不寻常的错误。之后减少我的代码的时间,我已经得出了以下的最小测试案例:C++:奇怪的是“私人”的错误
template <typename Dummy>
class Test {
struct CatDog {
static void meow()
{
CrazyHouse::TheCatDog::meow();
}
struct Dog {
static void bark();
};
};
struct CrazyHouse {
using TheCatDog = CatDog;
static void startMadness()
{
TheCatDog::meow();
TheCatDog::Dog::bark();
}
};
public:
static void init()
{
CrazyHouse::startMadness();
}
};
int main()
{
Test<void> t;
t.init();
}
使用g ++ 4.8.2的错误是:
test.cpp: In instantiation of 'static void Test<Dummy>::CatDog::meow() [with Dummy = void]':
test.cpp:19:29: required from 'static void Test<Dummy>::CrazyHouse::startMadness() [with Dummy = void]'
test.cpp:27:34: required from 'static void Test<Dummy>::init() [with Dummy = void]'
test.cpp:34:12: required from here
test.cpp:15:33: error: 'using TheCatDog = struct Test<void>::CatDog' is private
using TheCatDog = CatDog;
^
test.cpp:6:41: error: within this context
CrazyHouse::TheCatDog::meow();
^
锵3.4接受相同的代码。这里发生了什么,这是一个g ++的bug?
进行下列任何操作,从发生的历史停止错误:
- 谈到
Test
成一类,而不是一个模板类。 - 删除任何函数中的任何语句。
- 将
TheCatDog::Dog::bark();
更改为CatDog::Dog::bark();
。 - 删除
CrazyHouse
类并合并它的内容Test
。 - 删除
CatDog
类,将其内容合并到Test
中并将TheCatDog
别名更改为指向Test
。
最有可能的是。 – Shoe