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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:38:06+00:00 2026-05-29T10:38:06+00:00

Given this example, which includes a few overloads: #include <iostream> class T { public:

  • 0

Given this example, which includes a few overloads:

#include <iostream>

class T
{
   public:
      operator const wchar_t *(void) const
      {
         std::cout << "Conversion" << std::endl;
         return L"Testing";
      }
};

template <class Elem>
class A
{
};

template <class T>
void operator <<(A<T> &, const T *)
{
   std::cout << "1" << std::endl;
}

template <class T>
void operator <<(A<T> &, const void *)
{
   std::cout << "2" << std::endl;
}

int main(void)
{
   A<wchar_t> test;
   T          source;

   test << L"1";
   test << static_cast<const wchar_t *>(source);
   test << source;
}

And its output:

1
Conversion
1
Conversion
2

My question is – why is void operator <<(A<T> &, const void *) being called for the statement test << source;? Can anyone cite a specific part of the standard that covers this case?

  • 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-29T10:38:07+00:00Added an answer on May 29, 2026 at 10:38 am

    Because template argument deduction doesn’t take user defined implicit
    conversions into account. The result is that when you wrote:

    test << source;
    

    , the compiler could not find a suitable T for the first function
    template; it is trying to find a T such that T const* has the same
    type as your T, which isn’t possible. Argument deduction fails, and
    no instantiation of the template is added to the overload set. Since
    there’s no template argument in the second parameter of the second
    function template, there’s no argument deduction to fail, and the
    resulting instantiation becomes the only member of the overload set, and
    so ends up being chosen.

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

Sidebar

Related Questions

This is easier to explain with an example. Given these two classes: public class
Given this example: <img class=a /> <img /> <img class=a /> <img class=a id=active
This is just an example, but given the following model: class Foo(models.model): bar =
Given this example (which is a simplication of an example in the documentation for
Example: I have a selector like this, which I give to another method as
Given this example XML file: <doc> <tag> Hello ! </tag> <tag> My name is
Given this example, how would I return the result of the equation rather than
Given the example below, can someone please show me how this could be called?
Given the email address: Jim <jim@example.com> If I try to pass this to MailAddress
I'm trying to solve this problem : http://uva.onlinejudge.org/external/7/732.html . For the given example, they

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.