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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:14:09+00:00 2026-05-25T18:14:09+00:00

I was writing some java last night and I had two constructors that looked

  • 0

I was writing some java last night and I had two constructors that looked basically alike, except my default constructor provided some values to my object, it was something like this:

testObject(){
     width=5;
     height=12;
     depth=7;
     //other stuff is the same as the next one
}

testObject(int x, int y, int z){
    width=x; 
    height = y;
    depth = z;
    //All the other stuff is the same as default
}

So in this case, I was able to convert the code to do this instead:

testObject(){
    this(5,12,7);
}

That sent the values from the default constructor back to the constructor as the 3-int constructor to be built as such. Is there any way to get this type of functionality in C++?

  • 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-25T18:14:10+00:00Added an answer on May 25, 2026 at 6:14 pm

    In C++0x, you can do this:

    TestObject() :TestObject{5, 12, 7} {}
    

    See Delegating Constructors for more details. (Curly braces not look familiar to you? They’re for preventing narrowing.)

    If you don’t have C++0x available yet, then in your case, you can use default arguments as mentioned in other answers here.

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

Sidebar

Related Questions

I am writing some Java code that authenticates to Active Directory using SASL GSSAPI.
I'm writing some acceptance tests for a java webapp that returns JSON objects. I
I'm writing some code in Java that needs to show file chooser and alert
recently I'm writing some functions that I take from Haskell and translate into Java.
I recently came across some odd behavior that involves Java's regex engine. When writing
I am currently in the process of writing some software in Java that I
How would I go about writing some code to allow access to a Java
I have some experience writing web applications in Java for class projects. My first
Please suggest some good resources to start writing Java Web services.
Me and some friends are writing a MORPG in Java, and we would like

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.