简体   繁体   中英

Is aggregate initialization with a new struct valid?

Would a phrase such as Struct* a = new Struct{1,2,3}; be valid?

It compiles and runs just fine, but I'm wondering if there's anything funky going on behind the scenes.

struct Struct {
    int a;
    int b;
    int c;
}

That code will allocate memory for a new Struct and initialize the members with 1, 2 and 3, and finally put the pointer to that structure into the variable a . I have no idea whether you call that funky, though.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM