aggregate-initialization Questions

2

Solved

It is possible to define a struct (a) that has no user-defined constructors, and (b) for which a default constructor cannot be generated. For example, Foo in the below: struct Baz { Baz(int) {} }...

2

Solved

I wonder, why declaration of std_arr in the following code generates an error, while c_arr compiles well: struct S { int a, b; }; S c_arr[] = {{1, 2}, {3, 4}}; // OK std::array<S, 2> ...
Oreopithecus asked 16/2, 2015 at 12:29

1

Solved

Is it allowed in standard: struct A { int a = 3; int b = 3; }; A a{0,1}; // ??? Is this class still aggregate? clang accepts this code, but gcc doesn't.
Cachou asked 25/11, 2014 at 3:51

2

Solved

struct S { int x; int y; }; std::atomic<S> asd{{1, 2}}; // what should this be? This doesn't work Edit: Both {{1, 2}} and ({1, 2}) work in g++, neither work in clang. Is there a workarou...

2

Solved

The section "Array Initialization" in Chapter 4, page 231 of "Thinking in Java, 2nd Edition" has this to say: Initializing arrays in C is error-prone and tedious. C++ uses aggregate initializ...
Enlistment asked 18/7, 2013 at 1:9

4

Solved

Suppose I have the following struct: struct sampleData { int x; int y; }; And when used, I want to initialize variables of sampleData type to a known state. sampleData sample = { 1, 2 } L...
Coleoptile asked 8/6, 2011 at 20:0

2

Solved

Lets say we have the following code: #include <iostream> #include <string> struct A { A() {} A(const A&) { std::cout << "Copy" << std::endl; } A(A&&) { std:...
Freespoken asked 8/6, 2011 at 1:56

© 2022 - 2024 — McMap. All rights reserved.