g++ 无法编译我的复杂模板实例化
g++ won't compile my complex template instantiation
我使用MinGW最新版本编译以下代码。我收到以下消息
y:/bbom/source/om0/basic/test.cpp: In static member function 'static void somecl
ass::init(class_object*)':
y:/bbom/source/om0/basic/test.cpp:68:50: error: no matching function for call to
'class_object::add_method(void (&)(object*, arch&))'
y:/bbom/source/om0/basic/test.cpp:68:50: note: candidate is:
y:/bbom/source/om0/basic/test.cpp:27:54: note: template<class p_function> void c
lass_object::add_method(typename p_function::funcion_type)
make.exe: *** [y:/bbom/bin/om0/basic/test.a] Error 1
这是我的代码从这个问题不需要的所有东西中脱掉衣服
#include <exception>
class exception : public std::exception
{
public:
exception() {}
exception(const exception &);
~exception() throw() {}
virtual const char *what() const throw();
};
typedef unsigned id, version;
class class_object;
class object
{
public:
virtual ~object() {}
void *get_method(id);
class_object *get_class_object();
};
class class_object : public object
{
public:
template <class p_function>
void add_method(typename p_function::funcion_type p)
{add_method2((void *)p, p_function::function_id);}
void add_method2(void *, id);
};
template <typename p_func, id p_id>
class function
{
public:
typedef p_func function_type;
enum {function_id = p_id, };
function(object *p) {m_func = (p_func)p->get_method(p_id);}
p_func m_func;
};
class iface : public object
{
public:
iface(object *p) : m_object(p) {}
static void init(class_object *) {}
object *m_object;
};
class arch;
class archivable : public iface
{
public:
typedef void (*archive_func_type)(object *, arch &);
typedef function<archive_func_type, 0x5afeb287> archive_type;
archivable(object *);
archive_type archive;
};
class someclass : public object
{
public:
static void archive(object *, arch &)
{
}
static void init(class_object *p)
{
p->add_method<archivable::archive_type>(archive);
// the compiler says this call cannot be matched to
// add_method declared in class 'class_object'
}
};
我在 class_object::add_method<中调用模板方法有什么问题...>()中调用模板方法有什么问题...>
您似乎错误地输入了function_type
test.cpp
第 27 行的funcion_type
。
错别字。 funcion_type
应该是function_type
.
相关文章:
- 从C++实例化QML
- 设计一个只能由特定类实例化的类(如果可能的话,通过make_unique)
- 如何创建一个空的全局类并在启动时实例化它
- 在两个类中共享相同的函数调用,并在不需要时避免空实例化
- 约束和显式模板实例化
- 为什么包含windows.h会产生语法错误,从而阻止类的实例化?(C2146,C2065)
- 对象实例化调用构造函数的次数太多
- 如何使用非默认构造函数实例化模板化类
- 静态数据成员模板专用化的实例化点在哪里
- 错误的cv::face FacemarkLBF实例化
- C++的解析器在可以区分比较和模板实例化之前会做什么?
- 为什么 gcc 和 clang 为函数模板的实例化生成不同的符号名称?
- 检查某些类型是否是模板类 std::optional 的实例化
- 我有一个对象,它将在整个程序的持续时间内实例化,但一个类成员不会,我应该动态分配它吗?
- 无法使用 SWIG 在 Python 中实例化C++类(获取属性错误)
- 模板化类构造函数的模板实例化
- 在 c++ 中的模板实例化中使用带有构造函数的类作为类型参数
- g++ 无法编译我的复杂模板实例化
- 具有复杂类型的C++模板实例化
- 复杂数据类型的模板实例化问题