|
From: Devin C. <dcc...@ya...> - 2002-02-17 16:43:23
|
> 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:
Oh, I know. They're wonderful-looking things. I'm currently only
using them as fancy dynamic arrays.
But while you can do a lot with vectors, vectors can do a lot with
you. I had Vec.size() in a conditional, and the conditional
consistently got it wrong. It worked, however, when I replaced
Vec.size() with a variable, Size, which had been intialized to
Vec.size() a line before.
That's only one reason I'm very cautious with vectors.
> 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.
There's a saying that goes 'It's a poor workman who blames his tools.'
And many times it's been my mistake; I'm a poor workman. But there
are other times when I've caught something funny going on. (push_back()
refusing to work was one of them.)
> I am confident that standard containers are better than built in arrays.
Absolutely true: the reason I'm using vectors is because arrays are
/worse./ The only thing I think arrays have to recommend them is that
they can be intialized like so:
char* frogs[4] = { "Green", "Tree", "Bull", "Muppet" };
(Yes, I know char* is frowned upon, but I've found some interesting
traps trying to initialize a string to a string constant of the form "Blah"
when passed as an argument.)
For my project, in which certain subclasses have great tracts of
constant data, this kind of initialization would be ideal.
> You can overload an operator as a global function
> e.g.
> vector<int> &operator=(vector<int>&a, const vector<int> &b)
> { ... }
Thank you :)
> or better define it as a template:
>
> template <class T>
> vector<T> &operator=(vector<T> &a, const vector<T> &b)
> { ... }
Templates I'm somewhat wary of; I'll deal with them when I have
to. Until then I'll stick with learning the ins and outs of what I /do/
know.
> 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++).
Unfortunately, that's beyond my resources. I don't have the money and the
demand in the university/city library for books that teach C++ is total.
I've
only managed to scrounge the texts I'm working with by good fortune.
And despite what I might say, C++ is 10,000% better. Partially, I think,
because the old Kernighan and Ritchie paradigm of 'only stupid people make
mistakes - are you a stupid person?' has been replaced by the strong-type-
checking 'Everyone makes mistakes, we'll help you catch them' theory.
> It is better. :)
You've said it three times now - it must be true!
--Devin Carless
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
|