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

  • Home
  • SEARCH
  • 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 6735155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:58:31+00:00 2026-05-26T10:58:31+00:00

I have 2 questions, both relating to how arguments between Python and C++ mix…

  • 0

I have 2 questions, both relating to how arguments between Python and C++ mix… I have a function in C++ which I am calling from python, and my function takes dates and strings.

Is a python str the same as a C++

class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >

And secondly, my function needs a date of type class boost::gregorian::date, does anyone know how I can give a date in python that will be read with the correct signature?

Help much appreciated! I hope this is a fairly simple problem, I’m just not very experienced with different types of signatures (which doesn’t bode well for my current experimentation into linking Python and C++)!

  • 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-05-26T10:58:31+00:00Added an answer on May 26, 2026 at 10:58 am

    Assuming that you are using boost::python, let me give you an idea of how to proceed in these cases. Rather than letting boost::python automatically wrap your function, you provide your own wrapping:

        namespace {
    
            void Foo_methodUsingDate( Foo* pointer, const object& dateObject )
            {
                boost::gregorian::date date = convertFromPython( dateObject );
    
                pointer->methodUsingDate( date );
            }
        }
    
        void wrap_Foo()
        {
            class_< Foo >( "Foo" )
                .def( "bar",
                    & Foo::bar
                    )
                .def( "foobar",
                    & Foo::foobar
                    )
                .def( "methodUsingDate",
                    & Foo_methodUsingDate
                    )
                ;
        }
    

    Of course you need to provide a method that converts a boost::python::object into a boost::gregorian::date object. You have to decide how to handle this. For instance, you could assume that the parameter is a sequence of three integers, or you could allow more complex way of passing the parameters, or define a new class that wraps the gregorian date and all of its method and exposes it directly to Python.

    As for your first question, when using boost::python std::strings are automatically converted to/from Python strings.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two questions.They both are concerning a void in C++,which I am trying
I have two questions: 1) How can I make an array which points to
I have two different questions(on both questions need to ignore spaces) How to print
I actually have two questions, both are probably simple, but for some odd reason
I have two questions related to function objects and function pointers, Question : 1
I have two questions regarding RewriteRule, but they're both closely related so I hope
I actually have two questions today, but they are both small :-) 1) Where
I have some questions about the object size with virtual. 1) virtual function class
I have two questions regarding binary search trees, both about empty trees. Is an
I have some questions as to which overloaded method would be called in certain

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.