This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Is there a difference in C++ between copy initialization and direct initialization?
What's the difference between explicit and implicit assignment in C++
Simple as that. What is the difference between
std::string a("abc");
and
std::string a = "abc";
Related
This question already has answers here:
what will happen when std::move with c style array or not movable object
(2 answers)
Can std::move move a built-in types or c pointer or array
(1 answer)
What is std::move(), and when should it be used?
(9 answers)
Closed 8 months ago.
I want to do something like this:
int data[4] = {1,2,3,4};
int otherData[4];
otherData = std::move(data);
compiler says invalid array assignment, so how can I transfer values from data to otherData
This question already has answers here:
What are the evaluation order guarantees introduced by C++17?
(3 answers)
Order of evaluation of assignment statement in C++
(4 answers)
Closed 4 years ago.
Consider this code:
std::unordered_map<int, std::string> data;
data[5] = foo();
In what order are data[5] and foo() processed? If foo() throws an exception, is the 5 item in data created or not?
If the behaviour depends on version of C++, how do those versions differ?
This question already has answers here:
What are the differences between C-like, constructor, and uniform initialization?
(2 answers)
Closed 5 years ago.
Why are there multiple ways of initializing variables in c++ instead of just one?
From my knowledge you can do these:
int x = 0;
int y (2);
int c {3};
Thanks!
Oh, it is because , all of datatypes are an object.
They all have blind initializers, that is same as the default-constructor(initializer) of the classes.
This question already has answers here:
Is there a difference between copy initialization and direct initialization?
(9 answers)
Direct Initialization vs Copy Initialization for Primitives
(4 answers)
Closed 9 years ago.
I read the following code in c++:
bool result(false);
is result initialized as false?
but are there any benefits to do it instead of:
bool result = false;
can anyone help?
This question already has answers here:
Why does (i|o)fstream take a const char* parameter for a file name?
(5 answers)
Closed 8 years ago.
Is there any reasons - other than historical - to justify the fact std::ifstream/std::ofstream class take a char* and not a std::string to be constructed?
No. The constructor from std::string was added in C++11.