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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:53:16+00:00 2026-06-18T07:53:16+00:00

Hello just wondering is it possible in C++03 to do something as following. I

  • 0

Hello just wondering is it possible in C++03 to do something as following. I have tried it but doesn’t work for me.

struct SomeClass{
int a,b,c,d;
};

SomeClass * temp  = new SomeClass();
*temp = { 1,2,3,4};

I did it but compiler gives me a warning that extended initalizers are only supported with C++11
Is there some other way to use double brace initalization when using new to create the object?
Constructors are not allowed

  • 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-18T07:53:17+00:00Added an answer on June 18, 2026 at 7:53 am

    I don’t think you can do this directly in C++03, but you can (perhaps) simplify the job compared to just brute force, with something you might think of as an “out of class constructor”:

    struct someclass{
        int a, b, c, d;
    };
    
    someclass make(int a, int b, int c, int d) { 
        someclass ret = {a, b, c, d};
        return ret;
    }
    
    int main(){
        someclass *s = new someclass();
    
        *s = make(1, 2, 3, 4);
    }
    

    It’s a pretty easy bet that any reasonably recent (and probably even most pretty old) C++ compiler will inline the function call, so the function call won’t impose any overhead. If you wanted to, you could also turn the function into a template, and overload it for different numbers of parameters, so you could do things like:

    someclass *s = new someclass();
    
    *s = make<someclass>(1, 2, 3, 4);
    
    otherclass *o = new otherclass();
    
    *o = make<otherclass>(1, 2);
    

    Ultimately, however, the big problem here is that you’re starting off on the wrong foot. Chances are that for (at least) the next year or two, you should simply forget that C++ has new expressions at all. Feeling like you need it (especially in a case like this) is a fairly good sign that you haven’t adapted to C++ very well yet, and are still trying to write Java.

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

Sidebar

Related Questions

hello i have just start using Raphael but i'm very confused in the following
Hello guys. I think it isn't possible just using PHP, but just to be
Just wondering if it was possible to not split the following steps... Button b
Hello I'm just wondering about something in Python3.x. What is the foo in def
Hello fellow Computer People! I could do this myself, but was just wondering if
Hello just wondering why firbug is stating NaN even when these inputs have information
I'm just wondering what's more costly, something like: echo Hello world, my name is
Hello I was wondering whether this is possible. I have a horizontal menu created
Hello was just wondering if my app will get rejected using the following code:
gcc (GCC) 4.6.3 c89 Hello, I am just wondering if this is the best

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.