aggregate-initialization Questions
1
There is a struct containing POD and default constructor deleted. Trying to aggregate-initalize an instance of the struct results in compilation error in g++9.1 when compiled with -std=c++2a....
Tribune asked 22/7, 2019 at 21:8
0
It's a fairly common idiom in the Win32 standard library to make the first member of structs be the size of the struct, like so:
#include <cstddef>
struct wrapped_float
{
std::size_t value...
Widener asked 18/7, 2019 at 22:33
1
Solved
C++17's aggregate initialization for base class is awesome, but it is verbose when the base is only there to provide some functions (so no data members).
Here is minimal example:
#include <cst...
Esque asked 9/4, 2019 at 12:6
8
Solved
C++0x is going to make the following code and similar code ill-formed, because it requires a so-called narrowing conversion of a double to a int.
int a[] = { 1.0 };
I'm wondering whether this k...
Antonietta asked 13/12, 2010 at 22:33
2
Solved
I am hoping someone can give me the technical details of why the following will not compile, and if possible, a work around.
I have an existing struct called Foo, and code which uses initializer l...
Obstreperous asked 8/12, 2018 at 0:51
3
Solved
The naive, optimistic and oh.. so wrong view of the c++11 uniform initialization syntax
I thought that since C++11 user-defined type objects should be constructed with the new {...} syntax instead...
Touchmenot asked 29/11, 2015 at 21:22
1
Solved
Came across a non-common bit of c++ initialization code that seems to work fine with the following...
struct sfoobar { char bar[10]; char foo[10]; };
...
sfoobar x { 0 };
Is this an acceptable m...
Cenozoic asked 24/4, 2018 at 3:0
2
Solved
I basically try to write my own game engine for practice and personal use (I know, it's a nearly impossible task, but as I said, it's mostly for learning new things).
Currently, I'm working on my ...
Heterocyclic asked 16/1, 2018 at 17:27
1
Solved
The C++ standard library has std::is_constructible<Class, T...> to check if a class can be constructed from the given types as arguments.
For example, if I have a class MyClass which has a c...
Ier asked 19/12, 2017 at 8:32
1
Solved
I compiled some code with GCC with -Wall and -Wextra enabled. This code produces a warning:
struct A { A(int) {} };
struct B {};
struct C : A, B {};
int main() {
(void) C{1};
}
main.cpp: In ...
Gwyngwyneth asked 10/12, 2017 at 5:51
1
Solved
Given the example here below, I was surprised to find that despite the default constructor explicitly being deleted (or made default for that matter), aggregate initialization remained possib...
Lilian asked 27/10, 2017 at 9:6
3
Solved
Consider this code:
#include <variant>
struct x {
int y;
};
int main() {
std::variant<x> v(std::in_place_type<x>, {3}); /*1*/
return std::get<x>(v).y;
}
This does no...
Headsail asked 3/10, 2017 at 8:41
2
Solved
Could anyone help me with the following problem?
There is a simple code:
#include <vector>
struct A {
std::vector<int> vec;
};
void func (A &&a = {}) {}
int main()
{
func...
Ramberg asked 16/6, 2017 at 11:29
2
Solved
Consider the following function
template <class... T, class... U>
void f(std::tuple<T...> t, std::tuple<U...> u)
{
std::cout << sizeof...(T) << " " << sizeof.....
Dissonance asked 5/6, 2017 at 4:41
2
This is the n-th question about this, but I couldn't find exact duplicate...
Suppose the following code:
#include <iostream>
struct S {
int x;
int y;
};
class C {
public:
S s;
C() : s...
Rabinowitz asked 5/4, 2017 at 14:28
4
I have two types of structure variable initialization in my code.
Example
#include<iostream>
#include<string>
using namespace std;
struct Data{
int arr[5];
float x;
};
int main(){...
Faulk asked 23/11, 2016 at 6:2
3
Solved
I have found that the possibility of usage of initializer list syntax for a class depends on whether or not the class fields have default values. Why?
To be precise, consider the following code:
...
Corselet asked 29/6, 2016 at 12:24
2
Solved
Consider the following example:
#include <iostream>
#include <string>
struct ABC
{
std::string str;
unsigned int id ;/* = 0 : error: no matching constructor for initialization ...
Aq asked 9/3, 2016 at 12:10
0
Is it possible to define as private the aggregate initialization for an aggregate class? I would like that the class can only be aggregate-initialized by its own static private members.
Example:
...
Inclining asked 4/3, 2016 at 10:2
1
Solved
I have a struct which contains bit-fields:
struct Foo {
unsigned a : 16, b : 16;
};
And I want to know if I can use aggregate initialization on it's bit-fields. For example:
struct Foo bar = {...
Dithionite asked 18/1, 2016 at 14:19
1
Solved
Say I want to refer to a member of an initializer_list that I already defined. Can I do it?
This code compiles and gives the expected: "13 55 " in both Visual Studio and gcc, I'd just like to know...
Outdoor asked 20/11, 2015 at 13:49
1
Solved
Consider the following code:
#include <array>
struct A
{
int a;
int b;
};
static std::array<A, 4> x1 =
{
{ 1, 2 },
{ 3, 4 },
{ 5, 6 },
{ 7, 8 }
};
static std::array<A, 4>...
Cranage asked 16/7, 2015 at 9:6
3
This works:
int arr[10] = {};
All elements of arr are value-initialized to zero.
Why doesn't this work:
std::array<int, 10> arr({});
I get the following warning from g++ (version 4.8....
Sounder asked 7/7, 2015 at 14:48
1
The following is a quote from Effective Modern C++ (page 55):
"Suppose that you use an empty set of braces to construct an object that supports default constructor and also supports std::initial...
Scapolite asked 7/7, 2015 at 20:11
2
Solved
Suppose there's an std::array to be initialized. It's okay if using double braces:
std::array<int, 2> x = {{0, 1}};
std::array<int, 2> x{{0, 1}};
It's also okay to use single braces ...
Hoopoe asked 7/6, 2013 at 13:45
© 2022 - 2024 — McMap. All rights reserved.