在类成员函数内传递模板类作为模板模板参数
Passing template class as template template parameter inside class member function
我有一个项目需要使用GCC-4.4.7和GCC-4.9.0进行编译。
我们使用的代码将模板化类作为模板模板参数传递给另一个类。虽然代码在GCC-4.9.0上编译良好,但在GCC-4.4.7上失败。
以下是错误的再现:
#include <iostream>
using namespace std;
struct E
{
int a;
E(int b) : a(b) {}
};
template<template<int B> class C, int D> struct A
{
void print()
{
E e(D);
cout << e.a << endl;
}
int a;
};
template<int B> struct C
{
const static int a = B;
void print()
{
A<C, B> a;
a.print();
}
};
int main() {
C<3> c;
c.print();
return 0;
}
论编译:
[swarup@localhost ~]$ g++-4.9 Test.cpp -o Test
[swarup@localhost ~]$
[swarup@localhost ~]$ g++-4.4 Test.cpp -o Test
Test.cpp:43: error: type/value mismatch at argument 1 in template parameter list for ‘template<template<int B> class C, int D> struct A’
Test.cpp:43: error: expected a class template, got ‘C<B>’
Test.cpp:43: error: invalid type in declaration before ‘;’ token
Test.cpp:44: error: request for member ‘print’ in ‘a’, which is of non-class type ‘int’
如何纠正错误并正确地使用GCC-4.4.7进行编译?
注意:仅限C++98标准,该代码非常旧
C
的名称查找会找到注入的类名,而您使用的古代编译器不支持将其用作模板名称。
限定名称。
A< ::C,B> a;
相关文章:
- 基于另一个成员参数将函数调用从类传递给它的一个成员
- 使用指向成员的指针将成员函数作为参数传递
- 如何将lambda作为模板类的成员函数参数
- 将成员函数指针作为参数传递给模板方法
- c++构造函数成员初始化:传递参数
- 使用带有 ref 参数的成员函数创建线程时出现编译错误
- 如何将成员函数作为回调参数传递给需要"typedef-ed"自由函数指针的函数?
- 模板化检查是否存在带有参数列表的类成员函数?
- 如何将类成员方法的参数列表自动填充写入可变参数?
- 为什么我需要在成员发起器列表中重复基类的模板参数?
- C++向量默认为成员参数
- 将成员函数作为构造函数参数调用时出错 "Variable is not a type name"
- 可变参数模板参数扩展 类型为 std::function 的类成员
- 绑定到可变参数成员函数
- C/C++ 包含点的宏参数(成员访问运算符)
- 将const char * const参数成员分配给新值
- 基于模板参数成员函数参数的模板专用化
- 如何访问可变参数成员
- 可变类参数成员变量的异构存储
- 非模板类中的可变参数成员