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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:17:21+00:00 2026-05-26T17:17:21+00:00

I wanted to somehow extend the Microsoft type _variant_t so it accepts implicit/explicit conversions

  • 0

I wanted to somehow extend the Microsoft type _variant_t so it accepts implicit/explicit conversions to/from additional types. To do so, I wrote the following class:

class value_type
{
  public:
    /* Constructors */
    value_type(const std::string& str) : m_variant(str.c_str()) {}
    template <typename Type> value_type(const Type& value) : m_variant(value) {}

    /* Conversion operators */
    operator const _variant_t&() const { return m_variant; }
    operator std::string() const { return static_cast<const char*>(m_variant); }
    template <typename Type> operator Type() const { return static_cast<Type>(m_variant); }
  private:
    _variant_t m_variant;
};

That is, if every instance of _variant_t in the code is replaced with value_type, it “works” the same.

Lets consider the following function, which returns a _variant_t:

_variant_t foo();

If I write:

std::string bar()
{
  value_type v = foo();
  return v;
}

It compiles just fine.

But if I change the previous code like that:

std::string bar()
{
  return value_type(foo());
}

or:

std::string bar()
{
  return static_cast<std::string>(value_type(foo()));
}

The compilation fails with the following message:

configuration.cpp(41) : error C2668: ‘std::basic_string<_Elem,_Traits,_Ax>::basic_string’ : ambiguous call to overloaded function

If I remove the template <typename Type> operator Type... line, everything compiles.

Now I understand what the compilater says (it doesn’t know which operator to use) but I don’t understand why: It would seem logical to use the operator std::string when converting to std::string. What am I missing ?

Thank you.

  • 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-26T17:17:22+00:00Added an answer on May 26, 2026 at 5:17 pm

    The problem is that string’s constructor is overloaded. So if returning involves invoking a string constructor, then there are multiple choices: argument could be converted to const char*, allocator<char> or string.

    static_cast<string>(x) is the same as string(x).

    I suppose your first faulty example should read return string(foo());, not return value_type(foo());

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

Sidebar

Related Questions

I wanted to ask if the following scenario is somehow possible to happen. I
I'm currently worried that my application design is somehow awkward, so I wanted to
I wanted to allow the user to choose a currency from a list of
Is it possible to somehow listen to all perforce cammands issued from my machine
I wanted to ask if anyone knows how to move map from one div
I wanted to if it is possible to read a KeyID from an encrypted
I wanted to make this script work somehow, but i find that after you
I saw the following code, and wanted to use it for a simple activity
I Wanted to convert a c# code to j# and somehow managed to get
My php script downloads files from a remote server using cURL. I wanted to

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.