我在我的通用架构中使用如下所示的模式。它在 GCC 5.2.0 中编译并正确运行:
#include <iostream>
using namespace std;
template<class Baz>
class Foo
{
public:
void foo(){cout<<"Foo method";}
};
template<template<class> class FooType>
class BarBase: public FooType<int>
{
public:
double bar() {cout<<"Generic bar";}
};
template<template<class> class FooType>
class Bar: public BarBase<FooType>
{
};
template<>
class Bar<Foo>: public BarBase<Foo>
{
public:
void specialBar(){cout<<"Specialized bar";}
};
struct Aspect_Foo
{
template<class Baz>
using FooTrait = Foo<Baz>;
};
struct Aspect_Bar
{
template<template<class> class FooType>
using BarTrait = Bar<FooType>;
};
using Entity_NonAspectual = Bar<Foo>;
template<class FooAspect = Aspect_Foo,
class BarAspect = Aspect_Bar>
using Entity_Aspectual = typename BarAspect::template BarTrait<
FooAspect::template FooTrait>;
int main()
{
Entity_NonAspectual workingEntity;
workingEntity.foo();
workingEntity.bar();
workingEntity.specialBar();
Entity_Aspectual<> brokenEntity;
brokenEntity.foo();
brokenEntity.bar();
brokenEntity.specialBar();
}
但在 Clang 3.6 中,调用 BrokenEntity.specialBar() 时收到以下错误消息:
error: no member named 'specialBar' in 'Bar<FooTrait>'
这是 Clang 中的编译器错误吗?有解决方法吗?目前,我对使用 LLVM 的 Visual Studio 2013 非常满意,而让 GCC 与 VS 一起工作似乎很痛苦。我也愿意接受关于替代的基于 Windows 的 IDE/编译器组合的建议。
None
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)