I'm learning C++, and am rather confused as to the different types of initialization.
You can do:
T a;
which, as far as I can tell, will sometimes initialize a
and sometimes won't, depending on if T
has a default constructor.
You can also do:
T a(); // or
T a(1, 2, 3... args);
; (in some cases):
T a = 1; // implicitly converted to T sometimes?
; if there is no constructor:
T a = {1, 2, 3, 4, 5, 6};
; and also:
T a = T(1, 2, 3);
.
If you want to allocate on the heap, there's
T a = new T(1, 2, 3);
Is there anything else?
I'd like to know if a) I've got all the types of initialization covered and b) when to use each type?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…