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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:37:33+00:00 2026-05-25T03:37:33+00:00

Consider the following : class A { public: int xx; A(const A& other) {

  • 0

Consider the following :

class A
{
public:
    int xx;
    A(const A& other)
    {
        cout << "A cctor" << endl;
        /*  do some stuff */
    }

    A(int x) : xx(x) {}  /* conversion constructor */

    };


int main()
{    
    A a = 1;
    A other = a;
    return 0;
}

Is it right to say that CCtor converts from const to non-const in this case (and also in general) ?

Thanks ,Ron

  • 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-25T03:37:34+00:00Added an answer on May 25, 2026 at 3:37 am

    No idea what you mean. A(const A&) is a typical copy-ctor, which has a “read-only” access to its only argument. If you pass anything const, everything is fine. If you pass anything non-const, for ctor it becomes const. A a = 1 is a conversion ctor, as you said. A other = a is a copy ctor. What’s the question?

    Regarding your question’s title, in C++ there’s no fair way to convert const to non-const.

    class A
    {
    public:
        int xx;
        A(const A& other)
        {
            cout << "A cctor" << endl;
            /*  do some stuff */
            // other is const here - you can only call its
            // const methods and read all its data members            
        }
    
        A(int x) : xx(x) {}  /* conversion constructor */
            // at this point, x is not const, but it's a copy
            // of an object you've passed here, not the object itself
            // you can change x, it just doesn't matter - you
            // change the copy
        };
    
    
    int main()
    {    
        A a = 1; // a is not const, 1 is passed "by value", since it's primitive type
        A other = a; // a is not const, other is not const, a is passed by const reference
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider following class class test { public: test(int x){ cout<< test \n; } };
Consider the following class: class A { const int arr[2]; public: A() { }
consider the following: class X { public: X(int i) { cout << X(int i)
Consider the following: class A { public: const int c; // must not be
Consider the following class public class Class1 { public int A { get; set;
Consider the following class: class Something : ISomething { public void DoesSomething(int x) {
Consider the following code: class A { public: virtual void f() throw ( int
Please consider the following simple use case: public class Foo { public virtual int
Consider the following simplified objects and relationships: public class Job{ int JobId; String name;
Consider the following C++ code: class A { public: virtual void f()=0; }; int

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.