-1

我使用 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<...>() 中调用模板方法有什么问题

4

2 回答 2

5

看来您function_typefuncion_type第 27 行输入错误test.cpp

于 2012-06-25T12:18:22.390 回答
1

错字。 funcion_type应该是function_type

于 2012-06-25T12:21:41.053 回答