为什么我使用这些意大利面模板会"error: type name is not allowed"?
Why am I getting "error: type name is not allowed" with these spaghetti templates?
我有以下代码,带有一些模板的"意大利面条":
template <typename A, typename B, typename... Args>
class C {
/*... */
Bar& getBar() { /* ... */ }
public:
template <typename U>
static void Foo() {
A a = getA<U>();
Baz& bar = getBar();
bar.frob<U>(a); /* @@@ */
}
/*... */
}
/* no template */
class D : public C<SomeA, D, const SomeE&> { /* ... */ }
/* no template */
class F : public D { /* ... */}
当我尝试使用以下语句编译函数时:
D::Foo<F>();
我在标记为 @@@
的行上收到错误type name is not allowed
。我为什么会得到它?我知道当你尝试调用带有类型名称的函数时你会得到它,但它看起来不像我在这里这样做。
这是一个经典的模板歧义,不幸的是,如果您不了解它,很难注意到它。答:你需要写bar.template frob<U>(a);
原因:看这个问答。
相关文章:
- 由于"error C4430: missing type specifier - int assumed. Note: C++ does not support default-int",我现在无法编
- 为什么<error-type>从模板类切换时会出现 ?
- 如何修复" State Error (active) E0513 a value of type "const wchar_t *" cannot be assigned to an entity o
- 修复第三方代码:"error: ‘enable_if’ in namespace ‘std’ does not name a template type"
- 仅当链接函数 C++ 时,才会发生"Expression must have class type error"
- 返回的向量定义为 "std::vector<<error-type>, std::allocator<<error-type>>>
- 类定义内部"error: 'a' does not name a type"
- 为什么我有"Expected type specifier error"?
- 不知道为什么我会得到"error: does not name a type "
- 在 Solaris 机器上使用 SUN C++ 进行编译时"Error: incomplete type "无符号字符 [] " "
- 内存集调用位置的"error: expected constructor, destructor, or type conversion before '(' token"
- 非整数常量声明 - dev-error:在此范围内未声明"type"
- 在编辑器中"Error: type name is not allowed"消息,但不在编译期间
- 使用 "this" 关键字时的"Error: expression must have a pointer type"
- 使用 Boost.Log "error: target { simple_event_log.mc. } has no type" 构建 Boost
- 在C++,我收到一条消息"error: 'void*' is not a pointer-to-object type"
- 为什么我使用这些意大利面模板会"error: type name is not allowed"?
- 同时在另一个类中创建类的对象,该类仅具有参数化的 Ctor "error: x is not a type"
- 为什么我的代码会抛出"does not name a type error"?
- 获取"does not name a type error",但我正在命名一个类型