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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:36:17+00:00 2026-06-14T01:36:17+00:00

Background If a third party library has code like class ThirdPartyClass { public: int

  • 0

Background

If a third party library has code like

class ThirdPartyClass
{
public:
    int value;

    ThirdPartyClass(int i) : value(i) {}
    ThirdPartyClass(const std::string& s) : value(0) {}

};

bool ThirdPartyFunction(int a, const ThirdPartyClass obj)
{
    return a == obj.value;
}

Then it is possible to call like

ThirdPartyFunction(1, 1);
ThirdPartyFunction(1, std::string("Hello, World!"));

Question

Is it possible to extend this library (without modifying 3rd party code) to accept something like:

ThirdPartyFunction(1, "Hello, World!");   // const char* is not a string, implicit conversion fails

I want to avoid needing to write

ThirdPartyFunction(1, std::string("Hello, World!")); 

The above is simplified: in my real example ThirdPartyFunction is a stream operator and ThirdPartyClass is a type wrapper that allows interaction with stream manipulators.

  • 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-14T01:36:18+00:00Added an answer on June 14, 2026 at 1:36 am

    When I started this question I suspected it wasn’t possible to get what I want, because of other similar SO answers.

    By the time time I finished the question I came up with a work around that’s suits my needs, it is not really explicit conversion, so your mileage may vary depending on exactly what you need to achieve.

    I thought I might as well post it in case someone finds it useful.

    Work around

    Add the following definitions:

    class MyExtension : public ThirdPartyClass
    {
    public:
        MyExtension(const char*) : ThirdPartyClass(0) {}
    };
    
    bool ThirdPartyFunction(int a, MyExtension obj)
    {
        return ThirdPartyFunction(a, (ThirdPartyClass)obj);
    }
    

    Now it is possible to call

    ThirdPartyFunction(1, "Hello, World!");
    

    Note the above can be done without modifying third party code. It does rely on overloading the function, so if you had to do this for many functions it might not be feasible. You could also avoid the inheritance, and just convert from MyExtension to ThirdPartyClass in the overloaded function.

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

Sidebar

Related Questions

I've come across an issue with using a third party library, and am not
I'm using a third party library to render an image to a GDI DC
Background We are integrating third party email solution into our site. When a user
Say I have a third party Application that does background work, but prints out
My Zend_Log writers are sending data to third-party resources, like Amazon DynamoDB, for example.
Background I am writing a class library assembly in C# .NET 3.5 which is
as background I've got an embedded device that talks to a third party server
I would like to install some packages into a third-party site-packages directory (beyond the
Background I have a Windows service that uses various third-party DLLs to perform work
This is a slightly frustrating problem. I am using a third party library called

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.