g ++不会编译我的复杂模板实例化

时间:2012-06-25 12:13:32

标签: c++ templates mingw gnu

我使用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&lt; ...&gt;()

2 个答案:

答案 0 :(得分:5)

您似乎在function_type的第27行将funcion_type误认为test.cpp

答案 1 :(得分:1)

错字。 funcion_type应为function_type