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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:03:26+00:00 2026-06-08T21:03:26+00:00

From Effective Java 2ed Item 2: telescoping constructor pattern, in which you provide a

  • 0

From Effective Java 2ed Item 2:

telescoping constructor pattern, in which you provide a constructor
with only the required parameters, another with a single optional
parameter, a third with two optional parameters, and so on,
culminating in a constructor with all the optional parameter

Can I do the same in C++? I tried somthing like this:

MyClass::MyClass(QWidget *parent)
{   
    MyClass(NULL, NULL, NULL, parent);
}

MyClass::MyClass(QString title, QWidget *parent) 
{

    MyClass(title, NULL, NULL, parent);
}

MyClass::MyClass(QString title, QString rightButton, QWidget *parent)
{


    MyClass(title, NULL, rightButton, parent);
}



MyClass::MyClass(QString titleLabel, QString leftButtonLabel, QString rightButtonLabel, QWidget *parent)
: QWidget(parent)
{
      // construct the object
}

but it does not work. Any hint?

I am really new in C++ field so.. sorry for the newbee question

  • 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-06-08T21:03:27+00:00Added an answer on June 8, 2026 at 9:03 pm

    The easiest way is to supply default values to the constructor parameters.

    If that doesn’t work, you typically create an Init method that gets called by each constructor so that the code isn’t repeated.

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

Sidebar

Related Questions

According to Effective Java 2ed Item 2 telescoping constructor pattern , in which you
From Effective Java Second Edition, Item 28 : Do not use wildcard types as
From Effective Java 2nd edition item 67 page 266-268: The background thread calls s.removeObserver
I read Effective Java by Joshua Bloch and removed the 'Constant Interface anti-pattern' from
This is a follow-up from this question : Effective Java 2nd Edition, Item 17:
Consider the following from Effective Java Item 11 (Override clone judiciously) where Josh Bloch
from p.46 Effective Java Joshua Bloch. Item 9: ALways override hashCode when you override
This is from Effective Java Programs that use the int enum pattern are brittle.
A quote from Effective Java states that: A second legitimate use of finalizers concerns
Item 16 of Effective Java 2nd edition, favor composition over inheritance says the following

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.