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 6004547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:16:42+00:00 2026-05-23T01:16:42+00:00

I have a class that has two functions, both of which take a different

  • 0

I have a class that has two functions, both of which take a different set of parameters and both of which have default arguments like so:

void PlaySound(const std::string &soundName, int channel = 0, bool UseStoredPath = true);

void PlaySound(FMOD::Sound* sound, int channel = 0);

I’ve found how to do default argument overloads from the tutorial here

http://www.boost.org/doc/libs/1_37_0/libs/python/doc/v2/overloads.html

as well as how to do function overloads taking different parameter types here

http://boost.2283326.n4.nabble.com/Boost-Python-def-and-member-function-overloads-td2659648.html

and I end up doing something like this…

BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(PlaySoundFromFile, Engine::PlaySound, 1, 3)
BOOST_PYTHON_MODULE(EngineModule)
{
    class_<Engine>("Engine")
        //Sound
        .def("PlaySound", static_cast< void(Engine::*)(std::string, int, bool)>(&Engine::PlaySound));
}

The problem is I really have no idea how to use them together at the same time. I’d like to avoid having to change my base class function definitions.

Can someone who’s done this before, or knows how to do this help me out?

Thanks in advance

  • 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-23T01:16:43+00:00Added an answer on May 23, 2026 at 1:16 am

    This works for me:

    BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(
        PlaySoundFromFile, Engine::PlaySound, 1, 3)
    BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(
        PlaySoundFromFMOD, Engine::PlaySound, 1, 2)
    
    BOOST_PYTHON_MODULE(EngineModule)
    {
        class_<Engine>("Engine")
            .def("PlaySound", static_cast< void(Engine::*)
                (const std::string&, int, bool)>
                (&Engine::PlaySound), PlaySoundFromFile())
            .def("PlaySound", static_cast< void(Engine::*)
                (FMOD::Sound*, int)>
                (&Engine::PlaySound), PlaySoundFromFMOD())
        ;
    }
    

    The trick is that you need to tell each def() to use one of the overload specifiers (that seemed to be the biggest missing piece from what you had).

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

Sidebar

Related Questions

For example, I have a class that has two strings, one of which must
I have two classes that extend the activity class. Each class has it's own
I have a class that has an inner struct/class (I have decided which yet,
I have a class that has an output() method which returns a matplotlib Figure
I have a UIGestureRecognizer that I want to work on two different UIViews, both
I have a class that has no default constructor or assignment operator so it
I have a project that has mainly two objects, both inheriting from a base.
I have a class that has a decimal property accessible from multiple threads public
I have a class that has a Generic type G In my class model
I have a class that has some properties. And I want something that calculates

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.