[C++-sig] wrapping objects which inherit from std::map
Hi, I have the following: class foo : public std::map { } BOOST_PYTHON_MODULE(foo_ext) { using namespace boost::python; class_>("foo"); } The compiler complains that template arguments 1 and 2 are invalid. I'm certain my syntax is the problem. Can't anyone shed some light and help me correct my syntax? Thanks, Jeremy ___ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] wrapping objects which inherit from std::map
Jeremy Kie wrote: Hi, I have the following: class foo : public std::map { } You lack a semicolon here. (I also don't think it's a good idea to derive from standard containers, but that is an entirely different subject). BOOST_PYTHON_MODULE(foo_ext) { using namespace boost::python; class_>("foo"); There are three errors here, let's start with the simplest: You use '>>' in this line, which is a single token. You need to insert a whitespace there to make it two tokens, e.g. '> >'. Next, you use 'std::map' where you ought to use a type (such as 'std::map'. Finally, you only can declare bases that are themselves already exported to python via class_, so you need to start by exporting the base type std::map prior to 'foo'. Hope this helps, Stefan -- ...ich hab' noch einen Koffer in Berlin... ___ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] wrapping objects which inherit from std::map
Thanks for the direction Stefan. Apologies for the typos. What I was missing was the declaration of the "std::map" prior to my foo declaration. Yes, I agree with you regarding derivation from standard containers. My portion of the project is written in python, I'm trying to work with libraries written by another member of the team. With the addition of the "std::map" declaration, my compiler errors disappeared. Thanks, Jeremy On Wed, May 6, 2009 at 11:29 AM, Stefan Seefeld wrote: > Jeremy Kie wrote: > >> Hi, >> >> I have the following: >> >> class foo : public std::map { >> } >> > > You lack a semicolon here. (I also don't think it's a good idea to derive > from standard containers, but that is an entirely different subject). > > >> BOOST_PYTHON_MODULE(foo_ext) >> { >> using namespace boost::python; >> class_>("foo"); >> > > There are three errors here, let's start with the simplest: > > You use '>>' in this line, which is a single token. You need to insert a > whitespace there to make it two tokens, e.g. '> >'. > Next, you use 'std::map' where you ought to use a type (such as > 'std::map'. > Finally, you only can declare bases that are themselves already exported to > python via class_, so you need to start by exporting the base type > std::map prior to 'foo'. > > Hope this helps, > Stefan > > > -- > > ...ich hab' noch einen Koffer in Berlin... > > ___ > Cplusplus-sig mailing list > Cplusplus-sig@python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > ___ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] wrapping objects which inherit from std::map
Jeremy Kie wrote: With the addition of the "std::map" declaration, my compiler errors disappeared. That is very curious, as Python only discovers whether the base class has been exported or not at runtime. Thus it can't possibly result in a compiler error. Regards, Stefan -- ...ich hab' noch einen Koffer in Berlin... ___ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] wrapping objects which inherit from std::map
I think you are right. I removed the declaration of the std::map and it compiled without any errors. The problem must have been related to the missing template types. regards, Jeremy On Wed, May 6, 2009 at 11:56 AM, Stefan Seefeld wrote: > Jeremy Kie wrote: > >> >> With the addition of the "std::map" declaration, my compiler errors >> disappeared. >> > > That is very curious, as Python only discovers whether the base class has > been exported or not at runtime. Thus it can't possibly result in a compiler > error. > > Regards, > > Stefan > > > -- > > ...ich hab' noch einen Koffer in Berlin... > > ___ > Cplusplus-sig mailing list > Cplusplus-sig@python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > ___ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig
[C++-sig] boost python class inherits boost::asio::ip::tcp::socket
Hello, The library I am attempting to extend Python to contains a class which inherits from boost::asio::ip::tcp::socket. class tcp_client_socket : public boost::asio::ip::tcp::socket { // class members and functions go here... }; My question is whether or not it is a good idea to wrap this. My naive approach would be to something like: BOOST_PYTHON_MODULE(tcp_client_socket_ext) { using namespace boost::python; class_ >("tcp_client_socket"); } I did an initial compile and received many compiler errors. If anyone has done this before, what is the correct way to wrap such an object. Any help is greatly appreciated. Regards, -Jeremy ___ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig