| |
| |
| |
|
Page: 1 2 3 4 5 6 7 8 9
Comments:
<0> if you just started C++ you should NOT be using pointers <0> pointers are an advanced topic <0> you should be using simpler constructs like vector <1> we are coming from C to C++ <1> and i donno, my professor didnt tell anything regarding vexctor <1> he told to use char * <1> vector, even <0> anyway there is no way to get the size of a dynamic array back <1> another doubt, STL is a part of C++ or extension of C++ ? <0> part of C++ <1> he was telling as its an extentension. previously it was not in C++, now it got added <1> i told, its a part. but he is not agreying <0> your professor is 15 years out of date <1> :D <1> that is why am here.... :)) <1> dont mind, if i ask some stupid questions.... i might be asking to clear the doubt, what my professor has told..
<0> c++ is defined by ISO 14882, you ought to look there <0> hmm, where is the draft version of the new standard - does anyone know the url? <1> how do i delete the dynamically allocated array? is it delete []Myobject or delete MyObject[] ? <2> which one compiles? <1> he told just to use delete MyObject <-- that is not correct, i know <1> Tamama, am yet on the program. not yet finished to compile <0> DoIt, if he told you to just used delete MyObject, then he doesn't even know the very basics <1> right now am going with delete []MyObject <1> yyparse, he is a mix of c and C++. he cant distinguish between too.. he is mixing both <1> we cant do anything other than to listen <0> DoIt, seems like he doesn't know any C++ <1> you know, he asked to use #include<iostream.h>, and when he got error, he asked to use -Wno-deprectaed option to remove warning. lol <0> which university is this DoIt? <1> yyparse, dont laugh... this is not a university.. this is an industrial training, before joining to one of the multinational company <1> :P <1> i wont say the company name now... :D its a 3 letter word company whose name starts with 'I' <3> No great shock there then <1> :D , ofcoure, the company people will come and conduct interiew after the training, and those who all are clearing teh test will get into the company <1> i guess, atleast the interview will be standard... :)) <1> s/guess/hope <1> i will show my ***ignment after finishing it, please comment on it and correct me... :) <1> let me finish it... <4> Al Stevens (columnist for Dr. Dobbs) interviewed for that company once, and had to take a programming test. They told him that he had gotten the highest score to date, but since he didn't have a degree they wouldn't hire him. <4> He said he was glad that he wasn't hired by a company that stupid. <5> I got hired by IBM despite not having a degree... <5> I did NOT get hired by an insurance company because I didn't <0> I don't really care about companies not hiring non-graduates - that's up to them <5> but I talk to the companies that the insurance company talks to all the time :) <0> um, do you call people with degrees graduates in america? <5> you can, in context <0> that's what they're called here anyway - you can't be a graduate without having a degree! <1> hi.. here is the program that i did regarding the cl*** Word. http://www.rafb.net/paste/results/7wugps82.html <1> any comments to improve the codes, correct the errors, if there is any..... program is working fine.. :) <4> Yeah... use the standard C++ library. <4> std::string word; instead of char* word; <1> Solamente, am not supposed to use. i told already <4> You asked for improvements. <1> need to use char *. that is the ***ignmnt. <1> yeah, i know , i need to use STL. But as if now, i cant. i asking as per the current requirement of the code <4> Your Word(char* tmp) constructor is asking for trouble. The size of the string should be p***ed as the second parameter. <4> Otherwise, it's susceptible to crashes in the best case, and malicious buffer overflow attacks in the worst case. <4> Word(char* tmp, size_t tmpSize) : word(new char[tmpSize]), size(tmpSize) { strncpy(word, tmp, size); } <5> grrrr, microsoft is so freakin' CUTE! <4> Which points out the other improvement. Always initialize variables in the constructor initializer list, not in the body of the constructor. <1> yeah.. that i forgot <1> thankyou <4> Oops... <4> Word(char* tmp, size_t tmpSize) : word(new char[tmpSize + 1]), size(tmpSize) { strncpy(word, tmp, size); } <4> Oops again. <1> :D <4> Word(char* tmp, size_t tmpSize) : word(new char[tmpSize + 1]), size(tmpSize) { strncpy(word, tmp, size); word[size -1] = 0; } <4> This is why you use the standard library. <1> ha ha ha <4> Always, always, always use strncpy rather than strcpy. <4> Especially if your idiot professor won't let you use the standard library. <1> but, i am using a condition to check whether the size is less or not. right? <4> It doesn't matter. <1> why? can you make it clear? <4> Also, why are you calling strlen(word) if you are already storing the size? That's a waste of a function call. <4> Never call strlen if you already have a size lying around. <4> And in addWord, you should require a size parameter.
<4> Otherwise you're having to depend on the kindness of strangers. <1> yeah.. i added the size lateter.. so forgot to remove those part that i wrote before <4> Same for storeWord <5> Solamente: how's smartsam coming along? AJAX should have given it a distinct and active audience <4> addWord has a serious bug in it, to. <4> Get rid of ptr and just initialize word. <4> Actually, two serious bugs. <4> You ***ign word a pointer you just deleted, and you never delete what word already pointed to. <1> i need to do strcat. and what if the size is not enough? <4> Your professor is an idiot, did we cover that already? <1> sure. taht was the first thing we covered <1> Solamente, i didnt get this part. i deleted word( that is the part of memory word pointing to). then word is pointed to ptr. what is wrong in that? <4> You should allocate the new pointer, copy the contents of word to it, copy the new word to the end of that buffer (no strncat required, but it's probably easier that way for you), then delete [] word, then set word to the pointer you just allocated. <4> Ahhhh <4> I read your code wrong. <4> I though you had deleted ptr. My bad. <1> :) <1> np <4> strncat, btw. <1> sure, i will do the modification <4> Yeah, you might argue that since you allocated the word and you have the size, why bother? <4> Well, you should bother. <1> could you please explain? <4> Buffer overruns aren't likely to happen in a cl*** ***ignment, but they're killers in the real world. <1> didnt i take care for the buffer overrun? because, the strcpy part will only get executed if i have enough size. right? <4> Basically, never operate on a pointer unless you know the size of the data at the pointer. <4> What I'm getting at is to get in the habit of using strncpy and strncat. <1> okay okay.. sure, i do <4> Actually, what I'm getting at is use the C++ standard library so you don't *have* to use those god-awful functions, but that's another issue. <4> I never, ever, ever, ever use the C library. <1> :P <4> At least not the string functions. <1> Solamente, my next try to go with STL, even though he wont cover it <4> The rest, very rarely. <4> Your next try will be about half to one-third as much code, then. <1> if am using STL, am sure that, i can make the code one third of this <1> :) <1> one more doubt. i need to use cin.getline() right? that will be better. <1> atleast i can prevent not to accept more than the size of tmp <4> cl*** Word { std::string word; public: Word() {} Word(std::string tmp) : word(tmp) {} ~Word() {} void storeWord(std::string tmp) { word = tmp; } void addWord(std:string tmp) { word += tmp; } void displayWord() { if (!word.empty()) std::cout << "The word is \"" << word << "\"" << std::endl; } else { std::cout << "There is no word stored yet." << std::endl; } }; <4> Whee! <4> Yes, that will be better. <1> awwwwww <4> I'd add a copy constructor and ***igment operator, for completeness. <1> hmm, that part he will handle tomorrow. :)) <4> He's an idiot. <1> no doubt. <1> i did even send a mail to him, to make him aware of the standard. but he didnt even bother to read the mail. :P <6> most professors are <1> just told me that he got my mail... :d <6> actually, only my freshman year professors were idiots <6> and, that, unfortunately, is where courses like "intro to c++" are taught <4> I need to create an alias for "Your professor's an idiot" and save myself some typing. <6> solsux would be a good name <6> doh, already have that one mapped <4> I was thinking /khan <7> CTRL + SHIFT + I(diot) <1> can i call function in initializer list? <4> Of course. <1> okay. :) <4> It happens all the time, whether you know it or not. <8> 'morning <1> initializer list will process from right to left or left to right? <4> Neither. <9> Bottom to top? <4> Variables are initialized in the order that they are defined in the cl***. <1> okay... <4> So, don't do anything in an initializer list that is order-dependent. <1> order is depending upon how they are defined in the cl***, right? <4> That's why, in my rewrite of your constructor, I used the size that was p***ed to the constructor and not the size member. <4> Follow that rule and you'll be okay. <1> cool.. thanks
Return to
#c++ or Go to some related
logs:
#chatzone #AllNiteCafe #skype arab kiz hotmail il-haxix ta malta lesibians #linux #MissKitten Engine ubuntulooks is unsupported wyldroze
|
|