Skip to main content
Filter by
Sorted by
Tagged with
0 votes
0 answers
132 views

I have the below code with the below output: #include <iostream> #include <string> using namespace std; class P { public: P() { cout << "P() ctor" << ...
yapkm01's user avatar
  • 3,811
0 votes
1 answer
149 views

Got code review comment that my non-static class POD members be set to an invalid value. I agree that the initial value should be invalid. For my cases, 0 is invalid. Here's an example: class A { ...
PaulH's user avatar
  • 325
-1 votes
1 answer
107 views

c++ primer says : The default constructor is used automatically whenever an object is default or value initialized. Default initialization happens • When we define nonstatic variables (§ 2.2.1, p. 43)...
semicolon_missing's user avatar
3 votes
0 answers
121 views

I am trying to understand the rules governing the following initialization: struct A { const char* s_ptr; std::string str; }; A Foo() { return {}; } A a = Foo(); As per my understanding, a....
cbhattac's user avatar
  • 275
1 vote
1 answer
535 views

Per cppreference, the syntax for value initialization is: [..] T object {}; (since C++11) [..] It's already known that value-initialization is performed when an object is constructed with an empty ...
mada's user avatar
  • 2,033
1 vote
1 answer
588 views

If I have the following struct struct test { char *x; std::string y; }; And I initialize with test *t = new test(); That should value-initialize the object and do the following based on the ...
George's user avatar
  • 35
4 votes
3 answers
201 views

// Example program #include <iostream> #include <string> class T{ public: int x, y; T(){ std::cout << "T() constr called..." << std::endl; }; ...
Khamyl's user avatar
  • 406
0 votes
1 answer
36 views

If I can a parameter pack for the constructor arguments when I create a new object and I don't provide any constructor arguments then the result will be: new T(); which will value-initialize the ...
Zebrafish's user avatar
  • 16.3k
5 votes
2 answers
212 views

In short, why the code below behaves like described in the comments? struct A { A() = delete; //A(const A&) {} // uncommenting this... }; int main() { A a{}; // ... breaks this //...
Enlico's user avatar
  • 30.2k
6 votes
2 answers
474 views

If I have code like so class Node { public: Node *subnodes[10]; }; Node x = Node(); is it guaranteed after that code runs that x->subnodes[0] == nullptr? I'm no expert at C++, and I find C++ ...
mhd's user avatar
  • 125
3 votes
2 answers
403 views

Generally speaking, parentheses and braces are very different. For minimal reproducible example: #include <array> #include <vector> int main() { std::array<int, 2>{42, 42}; // ...
L. F.'s user avatar
  • 20.9k
3 votes
2 answers
139 views

In this piece of code: signed char v = -64; int n = 4; int x = v - '0' * (signed char)n; std::cout << x << std::endl; Should x be -5 or -261? In my understanding, the initializer ...
ABu's user avatar
  • 12.5k
8 votes
1 answer
1k views

By work here, I take to mean that std::atomic<T> a{} effectively zero initializes a. I have always been thinking so and have been practically using it until this. Before explaining my ...
Lingxi's user avatar
  • 15.1k
0 votes
2 answers
244 views

By the rules of value initialization. Value initialization occurs: 1,5) when a nameless temporary object is created with the initializer consisting of an empty pair of parentheses or braces (since ...
Darlyn's user avatar
  • 4,946
8 votes
2 answers
2k views

Why does the compiler (clang,gcc) not warn about narrowing conversions when doing this float a{3.1231231241234123512354123512341235123541235}; float a = {double(3....
Gabriel's user avatar
  • 9,562
5 votes
1 answer
648 views

I try to understand the first accepted answer of @bolov to the question Deleted default constructor. Objects can still be created... sometimes [1] It seems like I found a error there and so it messes ...
JenyaKh's user avatar
  • 2,558
7 votes
1 answer
245 views

Ben Voigt has pointed out here that: Zero initialization is one of the steps of static initialization. But you're right that you can't blindly substitute the latter (tag), since zero initialization ...
Jonathan Mee's user avatar
  • 39.1k
2 votes
1 answer
117 views

This question refers only to pre C++11. Consider the following seemingly broken code: struct X { X(){} // default user-provided constructor private: X(const X&){} }; int main() { X x ...
vsoftco's user avatar
  • 56.9k
3 votes
1 answer
3k views

I am playing with C++ value initialization. Therefore, I am printing uninitialized values in order to highlight (un)initialization depending on C++ standard version. But uninitialized values convey ...
oHo's user avatar
  • 55.1k
2 votes
1 answer
735 views

I am a C programmer trying to learn C++11, and I've run into something I don't understand. From what I can tell, the following issue is a difference between value initialization and direct ...
jefftime's user avatar
  • 440
2 votes
3 answers
552 views

Update: I'm looking to see if there's a way to zero-initialize the entire class at once, because technically, one can forget adding a '= 0' or '{}' after each member. One of the comments mentions that ...
haelix's user avatar
  • 4,655
-4 votes
3 answers
297 views

How to create a temporary value-initialized T* in standard C++? void foo( int ); void bar( int * ); int main() { foo( int() ); // works. a temporary int - value initialized. bar( ??? ); /...
Swordfish's user avatar
  • 13.2k
14 votes
1 answer
3k views

Cheers and hth. - Alf made a comment in this answer that value initialization is arguably a new feature of C++03 compared to C++98. I wonder what he meant. Is value initialization part of C++98? Is ...
Praxeolitic's user avatar
  • 24.4k
6 votes
1 answer
189 views

It's really unclear to me why anyone would name a particular form of initialization "value initialization". It sounds as though it's initializing the object by giving it a value... but that's what ...
Brian Bi's user avatar
  • 123k
10 votes
3 answers
5k views

Consider the code below struct B { B() : member{}{}; int member[10]; }; int main() { B b; } VS2013 compiler gives the following warning: warning C4351: new behavior: elements of array '...
user3701522's user avatar