[OT] general C++ question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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)?

Attachment: signature.asc
Description: This is a digitally signed message part

-- 
users mailing list
users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [EPEL Devel]     [Fedora Magazine]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Desktop]     [Fedora Fonts]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Fedora Sparc]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux