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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:20:16+00:00 2026-06-17T02:20:16+00:00

I have this class class XXX { public: XXX(struct yyy); XXX(std::string); private: struct xxx

  • 0

I have this class

class XXX {
    public:
        XXX(struct yyy);
        XXX(std::string);
    private:
        struct xxx data;
};

The first constructor (who works with a structure) is easy to implement. The second I can parte one string in a specific format, parse and I can extract the same structure.

My question is, in java I can do something like this:

XXX::XXX(std::string str) {

   struct yyy data;
   // do stuff with string and extract data
   this(data);
}

Using this(params) to call another constructor. In this case I can something similar?

Thanks

  • 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-17T02:20:17+00:00Added an answer on June 17, 2026 at 2:20 am

    The term you’re looking for is “constructor delegation” (or more generally, “chained constructors“). Prior to C++11, these didn’t exist in C++. But the syntax is just like invoking a base-class constructor:

    class Foo {
    public:
        Foo(int x) : Foo() {
            /* Specific construction goes here */
        }
        Foo(string x) : Foo() {
            /* Specific construction goes here */
        }
    private:
        Foo() { /* Common construction goes here */ }
    };
    

    If you’re not using C++11, the best you can do is define a private helper function to deal with the stuff common to all constructors (although this is annoying for stuff that you’d like to put in the initialization list). For example:

    class Foo {
    public:
        Foo(int x) {
            /* Specific construction goes here */
            ctor_helper();
        }
        Foo(string x) {
            /* Specific construction goes here */
            ctor_helper();
        }
    private:
        void ctor_helper() { /* Common "construction" goes here */ }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this class: Class B { private String D; private String E; }
i have this class public class Image { public string url { get; set;
I have this class: public static class CsvWriter { private static StreamWriter _writer =
I have this class: public class RateResultsSummary { public RateResultsSummary(string labelText, string dataText) {
To keep things simple, I have this class: public class Contact { public string
Suppose I have this class: public class GroceryListItem() { public GroceryList { get; private
I have this class file call SMSHelper.cs First I just wanted to know is
I have this class which i would like to map: public class Contract {
I have this class: class OriginalClass { string FirstItem; List<string> ListOfSecondItems; } I want
I have this class called SiteAsyncDownload.cs Here's the code: public class SiteAsyncDownloader { WebClient

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.