|
From: Daniel G. <sp...@ho...> - 2002-02-17 16:49:55
|
<html><div style='background-color:'><DIV>
<P>I thought vecotrs were only used with graphics? Can you use them at other times?<BR><BR></P></DIV>
<DIV></DIV>
<DIV></DIV>>From: "Devin Carless" <DCC...@YA...>
<DIV></DIV>>To: <DEV...@LI...>
<DIV></DIV>>Subject: Re: [Dev-C++] 'New Source File' bug
<DIV></DIV>>Date: Sun, 17 Feb 2002 11:46:47 -0500
<DIV></DIV>>
<DIV></DIV>> > I currently have little knowledge of the standard library and i am
<DIV></DIV>> > currrently learning about it (currently reading 16 chapter of TC++PL
<DIV></DIV>> > Special Edition). But with as many as i know so far you can do many
<DIV></DIV>> > things with vectors:
<DIV></DIV>>
<DIV></DIV>> Oh, I know. They're wonderful-looking things. I'm currently only
<DIV></DIV>>using them as fancy dynamic arrays.
<DIV></DIV>> But while you can do a lot with vectors, vectors can do a lot with
<DIV></DIV>>you. I had Vec.size() in a conditional, and the conditional
<DIV></DIV>>consistently got it wrong. It worked, however, when I replaced
<DIV></DIV>>Vec.size() with a variable, Size, which had been intialized to
<DIV></DIV>>Vec.size() a line before.
<DIV></DIV>> That's only one reason I'm very cautious with vectors.
<DIV></DIV>>
<DIV></DIV>> > Anyway i think it is our lack of knowledge, not vectors. When i finish
<DIV></DIV>> > the 16th chapter i will resend an email telling you how you can to
<DIV></DIV>> > assignments using vector constructors.
<DIV></DIV>>
<DIV></DIV>> There's a saying that goes 'It's a poor workman who blames his tools.'
<DIV></DIV>>And many times it's been my mistake; I'm a poor workman. But there
<DIV></DIV>>are other times when I've caught something funny going on. (push_back()
<DIV></DIV>>refusing to work was one of them.)
<DIV></DIV>>
<DIV></DIV>> > I am confident that standard containers are better than built in arrays.
<DIV></DIV>>
<DIV></DIV>> Absolutely true: the reason I'm using vectors is because arrays are
<DIV></DIV>>/worse./ The only thing I think arrays have to recommend them is that
<DIV></DIV>>they can be intialized like so:
<DIV></DIV>>
<DIV></DIV>> char* frogs[4] = { "Green", "Tree", "Bull", "Muppet" };
<DIV></DIV>>
<DIV></DIV>> (Yes, I know char* is frowned upon, but I've found some interesting
<DIV></DIV>>traps trying to initialize a string to a string constant of the form "Blah"
<DIV></DIV>>when passed as an argument.)
<DIV></DIV>> For my project, in which certain subclasses have great tracts of
<DIV></DIV>>constant data, this kind of initialization would be ideal.
<DIV></DIV>>
<DIV></DIV>> > You can overload an operator as a global function
<DIV></DIV>> > e.g.
<DIV></DIV>> > vector<INT> &operator=(vector<INT>&a, const vector<INT> &b)
<DIV></DIV>> > { ... }
<DIV></DIV>>
<DIV></DIV>> Thank you :)
<DIV></DIV>>
<DIV></DIV>> > or better define it as a template:
<DIV></DIV>> >
<DIV></DIV>> > template <CLASS T>
<DIV></DIV>> > vector<T> &operator=(vector<T> &a, const vector<T> &b)
<DIV></DIV>> > { ... }
<DIV></DIV>>
<DIV></DIV>> Templates I'm somewhat wary of; I'll deal with them when I have
<DIV></DIV>>to. Until then I'll stick with learning the ins and outs of what I /do/
<DIV></DIV>>know.
<DIV></DIV>>
<DIV></DIV>> > Yes, me too. But C++ is 10000% better. I suggest "The C++ Programming
<DIV></DIV>> > Language" 3rd edition or Special Edition by Bjarne Stroustrup (the
<DIV></DIV>> > creator of C++).
<DIV></DIV>>
<DIV></DIV>> Unfortunately, that's beyond my resources. I don't have the money and the
<DIV></DIV>>demand in the university/city library for books that teach C++ is total.
<DIV></DIV>>I've
<DIV></DIV>>only managed to scrounge the texts I'm working with by good fortune.
<DIV></DIV>> And despite what I might say, C++ is 10,000% better. Partially, I think,
<DIV></DIV>>because the old Kernighan and Ritchie paradigm of 'only stupid people make
<DIV></DIV>>mistakes - are you a stupid person?' has been replaced by the strong-type-
<DIV></DIV>>checking 'Everyone makes mistakes, we'll help you catch them' theory.
<DIV></DIV>>
<DIV></DIV>> > It is better. :)
<DIV></DIV>>
<DIV></DIV>>You've said it three times now - it must be true!
<DIV></DIV>>
<DIV></DIV>>--Devin Carless
<DIV></DIV>>
<DIV></DIV>>
<DIV></DIV>>_________________________________________________________
<DIV></DIV>>Do You Yahoo!?
<DIV></DIV>>Get your free @yahoo.com address at http://mail.yahoo.com
<DIV></DIV>>
<DIV></DIV>>
<DIV></DIV>>_______________________________________________
<DIV></DIV>>Dev-cpp-users mailing list
<DIV></DIV>>Dev...@li...
<DIV></DIV>>https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
<DIV></DIV></div><br clear=all><hr>Join the worlds largest e-mail service with MSN Hotmail. <a href='http://go.msn.com/bql/hmtag4_etl_EN.asp'>Click Here</a><br></html>
|