相关疑难解决方法(0)

无法访问vc ++ 10中的模板专用继承

以下代码使用GCC 4.4.6和Comeau 4.3.10进行编译.

#include <iostream>

struct A { int name; };
template<typename T> struct C : T { using T::name; };
struct B : private A { friend struct C<B>; };

int main()
{
    C<B> o;
    o.name = 0;
}
Run Code Online (Sandbox Code Playgroud)

它在VC++ 10中给出以下错误:

main.cpp(4): error C2877: 'A::name' is not accessible from  'A'
main.cpp(10): error C2247: 'A::name' not accessible because 'B' uses 'private' to inherit from 'A'
Run Code Online (Sandbox Code Playgroud)

什么是允许的良好的交叉编译器解决方案o.name = 0;

注意:添加using A::nameB处理问题,但将A::name成员发布给每个人,而它应该只对特定模板实例可见,即C<B> …

c++ templates visual-c++ private-inheritance

7
推荐指数
1
解决办法
283
查看次数

标签 统计

c++ ×1

private-inheritance ×1

templates ×1

visual-c++ ×1