KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
class C { public: C() : arr({1,2,3}) //doesn't compile {} /* C() : arr{1,2,3} //doesn't compile either {} */ private: int arr[3]; }; I believe the reason is that arrays can be initialized only with = syntax, that is: int arr[3] = {1,3,4}; Questions How can I do what I want to do (that is, initialize an array in a constructor (not assigning elements in the body)). Is it even possible? Does the C++03 standard say anything special about initializing aggregates (including arrays) in ctor initializers? Or the invalidness of the above code is a corollary of some other rules? Does C++11 list initialization solve the problem? Note that I do not want to use std::array or another container to solve this problem.
Tags (comma-separated)
Save Edits
Cancel