How to mimic this std::vector behavior [duplicate]
This question already has an answer here:
Initializer list syntax in member initializer list using C++11
3 answers
C++ Supply initializer-list constructor for class template
1 answer
How can I make a class I define have a constructor that works like this:
vector<int> vec = {1,2,3,4};
c++11 constructor initializer-list
marked as duplicate by jww, Raymond Chen, sideshowbarker, eyllanesc, Makyen Nov 18 '18 at 6:55
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Initializer list syntax in member initializer list using C++11
3 answers
C++ Supply initializer-list constructor for class template
1 answer
How can I make a class I define have a constructor that works like this:
vector<int> vec = {1,2,3,4};
c++11 constructor initializer-list
marked as duplicate by jww, Raymond Chen, sideshowbarker, eyllanesc, Makyen Nov 18 '18 at 6:55
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
Look upstd::initializer_list
as a constructor argument.
– erip
Nov 18 '18 at 2:43
3
Possible duplicate of C++ Supply initializer-list constructor for class template and Initializer list syntax in member initializer list using C++11. Maybe related, Why is list initialization (using curly braces) better than the alternatives?
– jww
Nov 18 '18 at 2:47
@erip Ah! I was dumb, I didn't realize I would have to use an ititializer_list AND overload operator= to get this behavior.
– Shane Murphy
Nov 18 '18 at 3:12
The specific line you show does not requireoperator=
, it only uses a constructor. Something likevector<int> vec; vec = {1,2,3,4};
would indeed require an assignment operator.
– Igor Tandetnik
Nov 18 '18 at 4:47
add a comment |
This question already has an answer here:
Initializer list syntax in member initializer list using C++11
3 answers
C++ Supply initializer-list constructor for class template
1 answer
How can I make a class I define have a constructor that works like this:
vector<int> vec = {1,2,3,4};
c++11 constructor initializer-list
This question already has an answer here:
Initializer list syntax in member initializer list using C++11
3 answers
C++ Supply initializer-list constructor for class template
1 answer
How can I make a class I define have a constructor that works like this:
vector<int> vec = {1,2,3,4};
This question already has an answer here:
Initializer list syntax in member initializer list using C++11
3 answers
C++ Supply initializer-list constructor for class template
1 answer
c++11 constructor initializer-list
c++11 constructor initializer-list
edited Nov 18 '18 at 3:00
jww
52.9k39225493
52.9k39225493
asked Nov 18 '18 at 2:42
Shane MurphyShane Murphy
142
142
marked as duplicate by jww, Raymond Chen, sideshowbarker, eyllanesc, Makyen Nov 18 '18 at 6:55
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by jww, Raymond Chen, sideshowbarker, eyllanesc, Makyen Nov 18 '18 at 6:55
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
Look upstd::initializer_list
as a constructor argument.
– erip
Nov 18 '18 at 2:43
3
Possible duplicate of C++ Supply initializer-list constructor for class template and Initializer list syntax in member initializer list using C++11. Maybe related, Why is list initialization (using curly braces) better than the alternatives?
– jww
Nov 18 '18 at 2:47
@erip Ah! I was dumb, I didn't realize I would have to use an ititializer_list AND overload operator= to get this behavior.
– Shane Murphy
Nov 18 '18 at 3:12
The specific line you show does not requireoperator=
, it only uses a constructor. Something likevector<int> vec; vec = {1,2,3,4};
would indeed require an assignment operator.
– Igor Tandetnik
Nov 18 '18 at 4:47
add a comment |
Look upstd::initializer_list
as a constructor argument.
– erip
Nov 18 '18 at 2:43
3
Possible duplicate of C++ Supply initializer-list constructor for class template and Initializer list syntax in member initializer list using C++11. Maybe related, Why is list initialization (using curly braces) better than the alternatives?
– jww
Nov 18 '18 at 2:47
@erip Ah! I was dumb, I didn't realize I would have to use an ititializer_list AND overload operator= to get this behavior.
– Shane Murphy
Nov 18 '18 at 3:12
The specific line you show does not requireoperator=
, it only uses a constructor. Something likevector<int> vec; vec = {1,2,3,4};
would indeed require an assignment operator.
– Igor Tandetnik
Nov 18 '18 at 4:47
Look up
std::initializer_list
as a constructor argument.– erip
Nov 18 '18 at 2:43
Look up
std::initializer_list
as a constructor argument.– erip
Nov 18 '18 at 2:43
3
3
Possible duplicate of C++ Supply initializer-list constructor for class template and Initializer list syntax in member initializer list using C++11. Maybe related, Why is list initialization (using curly braces) better than the alternatives?
– jww
Nov 18 '18 at 2:47
Possible duplicate of C++ Supply initializer-list constructor for class template and Initializer list syntax in member initializer list using C++11. Maybe related, Why is list initialization (using curly braces) better than the alternatives?
– jww
Nov 18 '18 at 2:47
@erip Ah! I was dumb, I didn't realize I would have to use an ititializer_list AND overload operator= to get this behavior.
– Shane Murphy
Nov 18 '18 at 3:12
@erip Ah! I was dumb, I didn't realize I would have to use an ititializer_list AND overload operator= to get this behavior.
– Shane Murphy
Nov 18 '18 at 3:12
The specific line you show does not require
operator=
, it only uses a constructor. Something like vector<int> vec; vec = {1,2,3,4};
would indeed require an assignment operator.– Igor Tandetnik
Nov 18 '18 at 4:47
The specific line you show does not require
operator=
, it only uses a constructor. Something like vector<int> vec; vec = {1,2,3,4};
would indeed require an assignment operator.– Igor Tandetnik
Nov 18 '18 at 4:47
add a comment |
0
active
oldest
votes
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Look up
std::initializer_list
as a constructor argument.– erip
Nov 18 '18 at 2:43
3
Possible duplicate of C++ Supply initializer-list constructor for class template and Initializer list syntax in member initializer list using C++11. Maybe related, Why is list initialization (using curly braces) better than the alternatives?
– jww
Nov 18 '18 at 2:47
@erip Ah! I was dumb, I didn't realize I would have to use an ititializer_list AND overload operator= to get this behavior.
– Shane Murphy
Nov 18 '18 at 3:12
The specific line you show does not require
operator=
, it only uses a constructor. Something likevector<int> vec; vec = {1,2,3,4};
would indeed require an assignment operator.– Igor Tandetnik
Nov 18 '18 at 4:47