list-initialization Questions

2

Solved

Check out this simple program: int main() { float f2 = 7.2; // OK, with warning float f3 = 7.199999809265137; // OK, no warning float f4{ 7.2 }; // Fails float f5{ 7.199999809265137 }; // OK, ...
Woolsack asked 8/7, 2016 at 21:17

1

Solved

I have a question about the different meanings of a curly-brace enclosed list. I know that C++03 did not support C++11's initializer_list. Yet, even without the -std=c++11 compiler flag, gcc 6.3 w...
Sprat asked 20/6, 2017 at 13:39

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

Given the following: #include <stdio.h> class X; class Y { public: Y() { printf(" 1\n"); } // 1 // operator X(); // 2 }; class X { public: X(int) {} X(const Y& rhs) { printf(" 3\n...
Marnimarnia asked 1/6, 2017 at 11:43

1

Solved

I read about narrowing conversion on the cpp reference website. I kind of understood it but what i am not getting is that why is the error present only in the first line. long double ld = 3.14159...
Patellate asked 17/5, 2017 at 17:44

3

Solved

struct A { A(int) {} }; struct B { B(A) {} }; int main() { B b({0}); } The construction of b gives the following errors: In function 'int main()': 24:9: error: call of overloaded 'B(<bra...
Frondescence asked 28/4, 2017 at 5:11

3

Given code: struct Test { int a = 1; int b = 2; }; Test test1; Test test2{}; For test2 I am sure, that test2.a == 1 and test2.b == 2. Is it guaranteed (or not) the same for test1 (without {})...
Karole asked 17/4, 2017 at 16:5

2

Solved

I want to create a temporary copy of a const object and use it in a non-const way: struct S { S& f() { return *this; } }; int main() { const S a{}; S{a}.f(); // Error on this line return ...
Pasqualepasqueflower asked 31/3, 2017 at 11:13

2

Solved

In C++11, I have the following union: union SomeData { std::uint8_t Byte; std::uint16_t Word; std::uint32_t DWord; unsigned char String[128]; }; If I initialize the union thusly; SomeData d...
Magnification asked 1/3, 2017 at 14:56

1

Solved

Is new int[8]() equivalent to new int[8]{} in C++11? In other words: Does the C++11 standard guarantee each of new int[8]() and new int[8]{} returns a zero-initialized array?
Essence asked 26/12, 2016 at 6:34

3

Solved

I have the following code: class A { public: A(const unsigned int val) : value(val) {} unsigned int value; }; int main() { int val = 42; A a(val); A b{val}; // <--- Warning in GCC, erro...
Neurath asked 25/12, 2016 at 14:0

2

Solved

Based on this code struct Foo { Foo() { cout << "default ctor" << endl; } Foo(std::initializer_list<Foo> ilist) { cout << "initializer list" << endl; } ...
Mixologist asked 8/2, 2016 at 15:18

1

Solved

The question rose in context of this answer. Consider an example: struct foo { int value; operator int&(){ return value; } operator int(){ return value; } }; int main () { int &a(foo...
Orlan asked 10/12, 2016 at 18:53

2

Solved

Why does the compiler (clang,gcc) not warn about narrowing conversions when doing this float a{3.1231231241234123512354123512341235123541235}; float a = {double(3.123123124123412351235412351234123...
Impart asked 25/11, 2016 at 13:10

1

Solved

I was filing a GCC bug for this, but I'd rather double-check this. Consider the following programs: #include <utility> template<typename T, typename A> void F(A&& a) { T(std::...
Cholera asked 3/10, 2016 at 20:45

4

Solved

What does the statement return {}; in C++11 indicate, and when to use it instead of (say) return NULL; or return nullptr;
Ungotten asked 14/9, 2016 at 9:33

2

Solved

Consider the following code: struct A { int x; }; int main() { A a; A b{a}; } Is this program well-formed at C++11 standard? In my copy of N3797 it says 8.5.4 List initialization [dcl.ini...

2

Solved

I am trying the uniform intializer with the string class of C++. Below is the code: #include <iostream> #include <string> using namespace std; int main() { string str1 {"aaaaa"}; s...

1

Solved

There is a paragraph about guaranteed copy elision in c++ draft n4606 [dcl.init] 17.6: If the destination type is a (possibly cv-qualified) class type: If the initializer expression is a ...
Axum asked 6/8, 2016 at 8:1

2

I've recently read somewhere (can't remember where) about using braces to allow multiple user-defined conversions, but there seems to be a difference between conversion by constructor and conversio...
Fireproof asked 27/5, 2016 at 11:40

1

Solved

#include <iostream> #include <string> #include <typeinfo> #include <typeindex> #include <map> #include <vector> class Base{ public: virtual ~Base() {} }; cla...
Excitable asked 20/1, 2016 at 22:54

2

Solved

I'm trying to write a class based around mathematical vectors: template <unsigned N> class Vector{ public: Vector() = default; Vector(std::initializer_list<double> li) { *this = li;} ...
Indemnity asked 25/11, 2015 at 20:39

1

Solved

I came across this post variadic template function to concatenate std::vector containers suggesting the use of the following syntax: template<typename T> void append_to_vector(std::vector&lt...
Elliottellipse asked 10/11, 2015 at 0:17

1

Solved

Consider the following program: #include <iostream> int main() { int n = 3; int fact = 1; for(auto i{1};i<=n;i++) fact*=i; std::cout<<"fact of "<<n<<"...
Pyatt asked 3/11, 2015 at 13:25

2

Solved

Is it ok to write something like this typedef unsigned long DWORD; DWORD nBytesRead = {}; Will this variable contains 0 after this expression?
Medrek asked 18/9, 2015 at 9:40

© 2022 - 2024 — McMap. All rights reserved.