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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:39:10+00:00 2026-05-29T21:39:10+00:00

this is my short code class A { public: int x,y; A(int a=0, int

  • 0

this is my short code

class A {
public:
    int x,y;
    A(int a=0, int b=0) {
        x=a;y=b;
    }
};
int main() {
    A t[2] = {9,3};
    cout << t[0].x << " " << t[0].y << endl;
    cout << t[1].x << " " << t[1].y << endl;
}

Output is:

9 0
3 0

When i comment my constructor:

9 3
0 0

My question is: why is that? I’ve tried to overload everything i could figure, that means:copy constructor, constructor with one,two parameters, (coma,equality,[]) operators, but I don’t know what compiler generates that it can take 2 integers in one constructor and assign them to x,y. I even tried to overflow numbers in brackets{}, by putting {99999999999999999999,3} to see what compiler will yell but it says it can’t convert const int because of overflow, so I believe it must be conversion, but how?

  • 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-29T21:39:13+00:00Added an answer on May 29, 2026 at 9:39 pm

    You’re implicitly converting 9, and 3 to A.

    A small test will prove this:

    class A {
    public:
        int x,y;
        explicit A(int a=0, int b=0) {
            x=a;y=b;
        }
    };
    

    This will yield a compilation error.

    That means that your code translates to:

    A t[2] = {A(9),A(3)};
    

    Since commenting out the conversion constructor (let’s call it that, although I’m not sure it is), it will no longer be able to convert int to A.

    The second snippet will only initialize the first element.

    EDIT: To clarify, try the following test:

    int x[10] = {1,1,1};
    

    This will only initialize the first 3 elements of the array.

    Also, without the conversion constructor, try the following:

    A t[4] = {1,1,2,2};
    

    The first 2 A‘s will be initialized.

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

Sidebar

Related Questions

The code that I am presently using is as follows: My main class public
In short: For this code: Encoding.ASCII.GetBytes(‚) I want the output to be 130, but
Here is my code: main service class public class SimpleService extends Service { Timer
To help me better understand lambda I wrote this short snippet that rotates and
This may be very obvious question, pardon me if so. I have below code
Okay, sample code first; this is my attempt at communicating what it is that
class base { int a; protected: template<class T> class derived; public: base() {} virtual
Consider the following code: namespace ConsoleApplication1 { class Program { static void Main(string[] args)
I am using BroadcastReceiver class for receiving the sms. My main class code is:
Here is the code: import java.lang.*; import java.io.*; class string { public static void

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.