int i = 0; vs int i {0}; #18
-
This reduces two cycles to one cycle by using |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
▪ But generally why we use |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
What is the difference between Initializing And Assignment inside the constructor? & What is the advantage?
As you see there is an additional overhead of creation & assignment in the latter, which might be considered for user-defined classes. An Code Example: class Myclass {
public:
Myclass (unsigned int param) : param_ (param) {}
unsigned int param () const {
return param_;
}
private:
unsigned int param_;
}; In the above example:
It initializes a member When do you HAVE TO use the member Initializer list?You will have(rather forced) to use a Member Initializer list if:
|
Beta Was this translation helpful? Give feedback.
-
What is POD? |
Beta Was this translation helpful? Give feedback.
int i = 0;
is an old style of initializing variables in C and C++. FromC++11
onwards,initialization
andassignment
are different terms. Initialization is more effective for class member variables.Must read: https://www.learncpp.com/cpp-tutorial/variable-assignment-and-initialization/#:~:text=Variable%20assignment%20and%20initialization