[OT] general C++ question
Christoph Höger
choeger at cs.tu-berlin.de
Thu Sep 2 10:15:27 UTC 2010
Hi all,
I just learned about closures in the Boost library and wanted to write
some shorter code. To test, I used the following snippet:
#include <iostream>
#include <string>
#include <boost/function.hpp>
#include <boost/bind.hpp>
class FakeVisitor {
public:
virtual void visit(int e) {}
virtual void visit(std::string e) = 0;
};
template <typename T> class GenericVisitor : public FakeVisitor {
public:
boost::function<void (T e)> f;
virtual void visit(T e) { f(e); }
};
void print(int a, int i) {
std::cout << a << ":" << i << std::endl;
}
int main(int argc, char** argv) {
GenericVisitor<int> v;
v.f = boost::bind(&print, 0, _1);
v.visit((int) 1);
v.visit(std::string("hallo"));
//boost::bind(print, 1, _1)(2);
}
Apparently, it does not work. Does anyone know why GenericVisitor<int>
does not inherit visit(std::string)?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
Url : http://lists.fedoraproject.org/pipermail/users/attachments/20100902/5c499b4a/attachment.bin
More information about the users
mailing list