Skip to content

Instantly share code, notes, and snippets.

@jitpaul
Created April 5, 2020 22:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jitpaul/96cfd2434de50939b614bd916e5d375b to your computer and use it in GitHub Desktop.
Save jitpaul/96cfd2434de50939b614bd916e5d375b to your computer and use it in GitHub Desktop.
Initialization
#include <vector>
class B{};
class A{
B b;
public:
A(B b):b(b){}
};
int main(){
A a{B()}; // There is no ambiguity here.
int var1{}; // Zero-initialized to 0;
char* var2{};// Zero-initialized to nullptr;
std::vector v1{}; // Each member is zero-initialized
std::vector v2{1,2,3}; // Vector is initialized with
// 3 elements 1,2 and 3.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment