2011-12-21 3 views
0

Эта программа предназначена для создания библиотеки, позволяющей программистам на C++ имитировать схемы. Любые отзывы приветствуются. Ошибка, с которой я столкнулся с головоломками.boost :: function template class

wire.h файл

template<typename S> 
class wire 
{ 
    public: 
    // default constructor 
    wire() : _s() {} 

    // constructor with one parameter of type S 
    wire(S s) : _s(&s) {} 

    // converter to signal 
    operator S() const { return *_s; } 

    // resets the signal of the wire and return the signal 
    S operator()(S s) { *_s = s; return s; } 

    private: 
    // pointer to signal being carried 
    S *_s; 
}; 

// functor, returns the negation of the negation of the signal of the wire as a wire 
template<typename W> 
struct ww_not 
{ 
    W operator()(W w1) const { return ~w1; }; 
}; 

main.cpp

#include <iostream> 
#include <boost/function.hpp> 
#include "wire.h" 
typedef unsigned sig_type; 
typedef wire<sig_type> wire_type; 

main() 
{ 
    sig_type s1(0x2), s2(0x3), s3(0x5), s4(0x7), s5(0xb), s6(0xc), s7(0x11); 
    wire_type w1(s1), w2(s2), w3(s3), w4(s4), w5(s5), w6(s6), w7(s7); 

    boost::function<wire_type (wire_type)> _not; 
    //_not = &ww_not; 
    // error missing template type 
    _not = &ww_not<wire_type>; 
    // error: expected primary-expression before ';' token 
} 

Я пробовал несколько различных способов, и он должен работать.

ответ

3

ww_not класс функтор, который должен быть реализован, а не функция с адресом:

_not = ww_not<wire_type>(); 
+0

Иногда его легко упустить из виду очевидное. –