|
From: Ioannis V. <no...@ya...> - 2002-02-19 20:23:05
|
<http://run.to/noicys> -----Original Message----- From: dev...@li... [mailto:dev...@li...] On Behalf Of Devin Carless Sent: Tuesday, February 19, 2002 4:37 PM To: dev...@li... Subject: Re: [Dev-C++] 'New Source File' bug int array[]={1,2,3,4,5,6,7,8,9,10}; // one past the end vector<int>v3(&array[0], &array[10]); // Creates v3 having the values of array Ooo. I didn't know you could do that. The -only- source I have for initializing vectors in objects (ANSI-C++ won't let you specify a size if the vector is in an object) Huh? :) ANSI C++ lets you specify the size of a vector in any circumstance. uses a hack. The object's vector is declared without a size. In the constructor, a temp vector is declared /with/ a size, and the object's vector is equated to it. This has large time cost. Also for large vectors it has large space cost too. When the constructor ends, the temp vector goes out of scope. Problem solved, at the minor (hah) cost of some clarity. Large time/space cost for large vectors. We must try to avoid changing the size of the vector as also creating temporary ones. You can initialize them as i said, why to do these dirty tricks anymore? :) Ioannis * Ioannis Vranos * Programming pages: <http://www.noicys.d2g.com/> http://www.noicys.d2g.com * Alternative URL: <http://run.to/noicys> http://run.to/noicys |