Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9225451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:34:46+00:00 2026-06-18T04:34:46+00:00

Our group is developing a numeric framework using C++. We whould now like to

  • 0

Our group is developing a numeric framework using C++. We whould now like to wrap basic parts of our framework to be available in Python. Our weapon of choice is Boost.Python since we’re already Boost for other purposes as well. We solely use smart_ptrs to support polymorphism. The following snippet is a simple example of how we would apply the strategy pattern:

#include <boost/shared_ptr.hpp>
struct AbsStrategy
{
  virtual std::string talk( ) = 0;
};

typedef boost::shared_ptr<AbsStrategy> StrategyPtr;

struct Foo : AbsStrategy
{
  std::string talk( )
  {
    return "I am a Foo!";
  }
};

struct Bar : AbsStrategy
{
  std::string talk( )
  {
    return "I am a Bar!";
  }
};

struct Client
{
  Client( StrategyPtr strategy ) :
          myStrategy( strategy )
  {
  }

  bool checkStrategy( StrategyPtr strategy )
  {
    return ( strategy == myStrategy );
  }

  StrategyPtr myStrategy;
};

If I wrap the whole thing using Boost.Python like so

#include <boost/python.hpp>
using namespace boost::python;

BOOST_PYTHON_MODULE( BoostPython )
{
  class_<Foo>( "Foo" )
      .def( "talk", &Foo::talk );

  class_<Bar>( "Bar" )
      .def( "talk", &Bar::talk );

  class_<Client>( "Client", init<StrategyPtr>( ) )
      .def( "checkStrategy", &Client::checkStrategy );
}

the following warning pops up during compilation

C:/boost/include/boost-1_51/boost/python/object/instance.hpp:14:36: warning: type attributes ignored after type is already defined [-Wattributes]

When I try to use wrappers in python, I get the following errors

>>> from BoostPython import *
>>> foo = Foo()
>>> bar = Bar()
>>> client = Client(foo)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
Boost.Python.ArgumentError: Python argument types in
    Tree.__init__(Tree, Foo)
did not match C++ signature:
    __init__(_object*, boost::shared_ptr<AbsStrategy>)
>>> client = Client(bar)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
Boost.Python.ArgumentError: Python argument types in
    Tree.__init__(Tree, Bar)
did not match C++ signature:
    __init__(_object*, boost::shared_ptr<AbsStrategy>)

What is missing to make the whole thing work without changing our framework? The wrappers can be adapted freely of course.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T04:34:48+00:00Added an answer on June 18, 2026 at 4:34 am

    Ok I found the solution. One has to use implicitly_convertible in the module declaration as shown below.

    #include <boost/python.hpp>
    using namespace boost::python;
    
    BOOST_PYTHON_MODULE( BoostPython )
    {
      class_<Foo>( "Foo" )
          .def( "talk", &Foo::talk );
    
      class_<Bar>( "Bar" )
          .def( "talk", &Bar::talk );
    
      class_<Client>( "Client", init<StrategyPtr>( ) )
          .def( "checkStrategy", &Client::checkStrategy );
    
      implicitly_convertible<boost::shared_ptr<Foo> , StrategyPtr>();
      implicitly_convertible<boost::shared_ptr<Bar> , StrategyPtr>();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are developing multiple apps for our client which all can be used using
We are a group of students who are finishing up developing our windows phone
Our group is primarily Java developers with a few .NET folks like me. We
We're using CRM On-Demand for our Service Group and I'm running into an application
Our manager today has informed us that our group will now handle a new
Our group is somewhat new to JVM based development. We are developing applications that
In our dev group we have a raging debate regarding the naming convention for
A portion of our research group's program has auxiliary functionality provided by ctemplate library.
Our application is modulraized (Group of modules doing specific things). The modules have event
Our family has created a Flickr group in honor of a recently deceased relative.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.