   Question about using ...= {blah, blah, blah}
  Hi all.So, I am writing classes for vectors and matrices to be used for a simple 3D graphics program.  I want the vectors to be easy to use, so I''ve overloaded several operators, including [ ] (indexing).  What I want to know is, is there something I can do that allows me to treat an object of my type just like any other array, in terms of initializing all the entries?  If you''re dealing with integers or characters or whatever, you can do this:int arrayOfInts[5] = {1,2,3,4,5};char arrayOfChars[3] = {''a'', ''b'', ''c''};but with my class, I have to do this:ColVector myVect(5);myVect[0] = 1.0;myVect[1] = 2.0;myVect[2] = 3.0;myVect[3] = 4.0;myVect[4] = 5.0;Is there anything I can do (operator overloading etc) that lets me do something like this?myVect = {1.0, 2.0, 3.0, 4.0, 5.0};Maybe writing an assignment operator that accepts a double[] ?I don''t know how the compiler resolves the expression{1.0, 2.0, 3.0, 4.0, 5.0}I suppose if it resolves it as an array of floats or doubles, overloading an operator would work.  Anyone have any information, or tried this themselves? 
  This syntax is only possible during the initialisation   of POD-struct and array types. It cannot be used for an assignment, or with a type that has a constructor/destructor/that kind of machinery. It does not "resolve" as anything, no amount of overloading will help you here.“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”    — Brian W. Kernighan (C programming language co-inventor) [edited by - Fruny on February 4, 2004 11:20:40 PM];  There''s doesn''t appear to be an easy/standard way to do it.  If you want to initialize a vector with an array you can iterate through it and copy.something like:vector<int> v;int a[] = { 1, 2, 3, 4, 5};int N = sizeof (a) / sizeof (int);copy (a, a + N, back_inserter<v>; ;  Fruny is correct, but you did know that it is possible for class member initializer-list assignment, right? class C{public:int a, b, c;float f;};int main(){C c = { 3, 2, 4, 0.0f };return 0;}Class C is aggregatable when its members are public, not when private though.   blah blah blah. ;  Yup, class C is a POD-struct  “Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”    — Brian W. Kernighan (C programming language co-inventor);  Oh, math vectors, not the vector container.  Ugh, good thing I''m anonymous. ;  POD? Payable On Death? Where does the name come from, Fruny?   blah blah blah. ;  POD == Plain Old DataDo know where the name originally came from, but that''s the term used in the C++ Standard for those types of classes/structs. ;  "Plain Old Data" comes from the C++ Standard. That''s how C-compatible structs are named, since a struct is otherwise the same thing as a class. A POD-struct doesn''t have constructors, privated data...   “Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”    — Brian W. Kernighan (C programming language co-inventor);  Thanks Fruny.  Good to know that {...} does not resolve as anything to the compiler.Chris Hare, I didn't know you could do that.  So you just have to initialize them in the same order as they are declared in the class declaration?  This could be useful.  The thing is, the only data members in my class are a pointer to a double (gets initialized as an array) and an integer representing the size. It has to be a double* and not a double, because it points to an array whose size is only known when the constructor is called.  I have something like this: ColVector::ColVector(int sz): size(sz){entries = new double[size];for (int i=0; i<size; ++i)entries[i]=0;}Would I be able to initialize every entry in the array in the way you described? [edited by - RheniumIodide on February 4, 2004 12:10:42 AM] [edited by - RheniumIodide on February 4, 2004 12:12:13 AM]