如何創建對模板類中的模板函數的函數回調。以下是我迄今爲止:模板類的模板成員的函數句柄
template <typename SocketType>
class NettyPBSslSerializer {
...
template <typename Handler>
void async_read(google::protobuf::Message *pbmess,Handler handler) {
void (NettyPBSslSerializer<SocketType>::*f1)(
const boost::system::error_code&,std::size_t offset,google::protobuf::Message *pbmess,boost::tuple<Handler>)
=&NettyPBSslSerializer<SocketType>::async_read_varint <Handler> ;
boost::asio::async_read (socket_,
boost::asio::buffer(&read_buffer_.at(0), 9),
boost::asio::transfer_at_least(1),
boost::bind(f1,this,boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred, pbmess,boost::make_tuple(handler))
);
}
template <typename Handler>
void async_read_varint(const boost::system::error_code& e, std::size_t offset,google::protobuf::Message *pbmessp, boost::tuple<Handler> handler) {
}
....
SocketType socket_;
}
我用G ++收到以下錯誤
nettypbserializer.hpp|186| error: expected primary-expression before '>' token
nettypbserializer.hpp|186| error: expected primary-expression before ';' token
線186
=&NettyPBSslSerializer<SocketType>::async_read_varint <Handler> ;
我把它通過去除模板符編譯所以行186結束了: = NettyPBSslSerializer :: async_read_varint; 我不明白爲什麼這個工程雖然。有誰知道爲什麼? –