|
From: Ioannis V. <no...@ya...> - 2002-02-16 16:48:57
|
> -----Original Message-----
> From: dev...@li...
> [mailto:dev...@li...] On Behalf
> Of Devin Carless
> Sent: Saturday, February 16, 2002 6:20 PM
> To: dev...@li...
> Subject: Re: [Dev-C++] 'New Source File' bug
>
> >
> > What trouble.
>
> Initializing an array/vector of objects, of which some of the
> members are consts. That was my first problem. My second
> was push_back() decided to stop working. (This led me to
> look somewhat askance at vectors, and I still see them as
> exceedingly finicky things.) Initializing a vector to anything
> interesting including constants without using push_back() is
> difficult; I ultimately solved the problem by ripping out almost
> every const in my project (not without some satisfaction)
> and using a Set() function. (I implemented a rudimentary
I currently have little knowledge of the standard library and i am
currrently learning about it (currently reading 16 chapter of TC++PL
Special Edition). But with as many as i know so far you can do many
things with vectors:
const vector<int>::size_type SIZE=100;
vector<int>array(SIZE);
for(vector<int>::size_type i==0; i<SIZE; i++)
array[i]=...;
Anyway i think it is our lack of knowledge, not vectors. When i finish
the 16th chapter i will resend an email telling you how you can to
assignments using vector constructors.
> sort of data protection by only allowing anything to be
> changed if the Name member was set to the constant
> NULLSTR.)
> I've also had problems initializing vectors from arrays.
> Vectors can be initialized in a wonderful panoply of ways,
> all of which are thoroughly useless for my purposes. It's
> recently occurred to me that this is probably a job for an
> overloaded assignment operator. I'm not certain how to
> do this for a vector (while vectors are finicky, templates are
> just plain sticky, and I haven't read much about them
> because I don't expect to need them for a while.)
I am confident that standard containers are better than built in arrays.
You can overload an operator as a global function
e.g.
vector<int> &operator=(vector<int>&a, const vector<int> &b)
{ ... }
or better define it as a template:
template <class T>
vector<T> &operator=(vector<T> &a, const vector<T> &b)
{ ... }
> Most of my problems, I can see, stem from the fact that
> I learned (and loved) C long before ever setting eyes on
> C++.
Yes, me too. But C++ is 10000% better. I suggest "The C++ Programming
Language" 3rd edition or Special Edition by Bjarne Stroustrup (the
creator of C++).
>(My first reaction to C++ was 'They've turned
> something beautiful into a hideous bloated beast.') So I
No it is better.
> despise references with a hate the KKK can only dream of
> achieving, find consts to be a pain in the colon that extends
> all the way up the intestines, and find C++ is excessively
> schoolmarmish about initialization. (Don't get me wrong - I
> adore classes, inheritance,
> polymorphism and even strong typing. On the whole,
> it's a much better language.
It is better. :)
Ioannis
* Ioannis Vranos
* Programming pages: http://www.noicys.d2g.com
* Alternative URL: http://run.to/noicys
|