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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:24:40+00:00 2026-05-27T07:24:40+00:00

Consider a type bar which has user-defined conversion operators to references of type bar

  • 0

Consider a type bar which has user-defined conversion operators to references of type bar:

struct bar
{
  operator bar & ();
  operator const bar & () const;
};

When would these conversions be applied? Moreover, what does it imply if these operators were deleted? Is there any interesting use of either feature?

The following program does not appear to apply either conversion:

#include <iostream>

struct bar
{
  operator bar & ()
  {
    std::cout << "operator bar &()" << std::endl;
    return *this;
  }

  operator const bar & () const
  {
    std::cout << "operator const bar &() const" << std::endl;
    return *this;
  }
};

void foo(bar x)
{
}

int main()
{
  bar x;

  bar y = x;         // copy, no conversion

  y = x;             // assignment, no conversion

  foo(x);            // copy, no conversion

  y = (bar&)x;       // no output

  y = (const bar&)x; // no output

  return 0;
}
  • 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-27T07:24:41+00:00Added an answer on May 27, 2026 at 7:24 am

    C++11 §12.3.2

    A conversion function is never used to convert a (possibly cv-qualified) object to the (possibly cv-qualified) same object type (or a reference to it), to a (possibly cv-qualified) base class of that type (or a reference to it), or to (possibly cv-qualified) void

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

Sidebar

Related Questions

Consider the following code: struct Foo { }; struct Bar { explicit Bar(const Foo&)
I have a type which I consider use it as struct. It represents single
What would you consider to be the best exception type to throw when an
I need to obtain the type which was supplied when instantiating a template. Consider
Please consider the following Amount value type property which is marked as a nullable
Consider the following class, with the inner struct Y being used as a type,
Consider the following snippet: struct ObjectInterface { virtual ~ObjectInterface() {} virtual void Print(std::ostream& target)
Consider type like this one public interface IHaveGenericMethod { T1 Method<T1>(T1 parm); T2 Method<T1,T2>(T1
Let's consider a data type with many constructors: data T = Alpha Int |
Consider the following nested type: public class Book { private class Chapter { }

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.