2012-06-25 53 views
-1

我使用MinGW最新版本編譯下面的代碼。我得到的消息如下因素g ++不會編譯我的複雜模板實例

 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 <每一件事情我脫了衣服代碼.. >()

回答

5

看起來您錯誤地輸入function_type作爲funcion_typetest.cpp的第27行。

+0

你是對的,我感到羞愧:)謝謝你的回答 –

1

Typo。 funcion_type應該是function_type