Who finds it first... [closed] : [modified]
-
Ah good optimus! You've spotted the logical mistake I did when I put that code here and modified online. Sorry I've corrected the mistake. Look at the code again, you'd see it. Also check my reply to Vikram. Anyway you are dangerously close the bug! good luck :-D
I'm not sure but doesn't push_back already take a reference while you are passing a pointer to it?
-
I'm not sure but doesn't push_back already take a reference while you are passing a pointer to it?
-
Hey no,k now I'm pushing the string's value inside the vector , no refs... So ignore it ;).. find the bug.. just a clue. It's related to std::strings. :-D
Never worked that much with std::string but I will keep track :-D
-
std::string stSroucePath; std::string stDestPath; setSourcePath(&stSourcePath); setTargetPath(&stDestPath); if((stSourcePath.size==0)||(stDestPath.size==0))// should be `size()`swati m spots it! :-D happy coding dude ;) { prompt("Set the Directory paths!"); //Added! } else { int nRes = examineFile(stSourcePath.c_str()); if(nRes>0) { moveFilesToDest(&stDestPath); vec_stMovedFiles.push_back(&stDestPath); vec_stMovedFiles.push_back(stDestPath); return; } switch(nRes) { case -1: prompt("Protected!"); break; case -2: ... . . . } }
Find the dumb little evil bug inside..(Don't worry about the purpose of the code) It doesn't throw any exception but will screw up your application silently.
-
std::string stSroucePath; std::string stDestPath; setSourcePath(&stSourcePath); setTargetPath(&stDestPath); if((stSourcePath.size==0)||(stDestPath.size==0))// should be `size()`swati m spots it! :-D happy coding dude ;) { prompt("Set the Directory paths!"); //Added! } else { int nRes = examineFile(stSourcePath.c_str()); if(nRes>0) { moveFilesToDest(&stDestPath); vec_stMovedFiles.push_back(&stDestPath); vec_stMovedFiles.push_back(stDestPath); return; } switch(nRes) { case -1: prompt("Protected!"); break; case -2: ... . . . } }
Find the dumb little evil bug inside..(Don't worry about the purpose of the code) It doesn't throw any exception but will screw up your application silently.
if((stSourcePath.size==0)||(stDestPath.size==0)) Isn't size a function?? It should probably be if((stSourcePath.size()==0)||(stDestPath.size()==0)) and you should be getting a compilation error?!!
"a child will grow up to become an adult, but you can never stop the adult from acting like a child"
-
std::string stSroucePath; std::string stDestPath; setSourcePath(&stSourcePath); setTargetPath(&stDestPath); if((stSourcePath.size==0)||(stDestPath.size==0))// should be `size()`swati m spots it! :-D happy coding dude ;) { prompt("Set the Directory paths!"); //Added! } else { int nRes = examineFile(stSourcePath.c_str()); if(nRes>0) { moveFilesToDest(&stDestPath); vec_stMovedFiles.push_back(&stDestPath); vec_stMovedFiles.push_back(stDestPath); return; } switch(nRes) { case -1: prompt("Protected!"); break; case -2: ... . . . } }
Find the dumb little evil bug inside..(Don't worry about the purpose of the code) It doesn't throw any exception but will screw up your application silently.
**std::string stSroucePath;** std::string stDestPath; setSourcePath(&stSourcePath); setTargetPath(&stDestPath); if((stSourcePath.size==0)||(stDestPath.size==0))
stSroucePath ... it should be stSourcePath ... it is a typo? Em i right? -- modified at 5:42 Tuesday 17th July, 2007 -
if((stSourcePath.size==0)||(stDestPath.size==0)) Isn't size a function?? It should probably be if((stSourcePath.size()==0)||(stDestPath.size()==0)) and you should be getting a compilation error?!!
"a child will grow up to become an adult, but you can never stop the adult from acting like a child"
-
**std::string stSroucePath;** std::string stDestPath; setSourcePath(&stSourcePath); setTargetPath(&stDestPath); if((stSourcePath.size==0)||(stDestPath.size==0))
stSroucePath ... it should be stSourcePath ... it is a typo? Em i right? -- modified at 5:42 Tuesday 17th July, 2007 -
**std::string stSroucePath;** std::string stDestPath; setSourcePath(&stSourcePath); setTargetPath(&stDestPath); if((stSourcePath.size==0)||(stDestPath.size==0))
stSroucePath ... it should be stSourcePath ... it is a typo? Em i right? -- modified at 5:42 Tuesday 17th July, 2007 -
Hey, I saw that! I was fairly sure it was C++, but noticed size didn't have the parantheses. That's why I said the language looks alien. I was looking for a runtime error. :| But Swathi can have your beer; I'm a teetotaller. ;P
Cheers, Vıkram.
After all is said and done, much is said and little is done.
-
Hey, I saw that! I was fairly sure it was C++, but noticed size didn't have the parantheses. That's why I said the language looks alien. I was looking for a runtime error. :| But Swathi can have your beer; I'm a teetotaller. ;P
Cheers, Vıkram.
After all is said and done, much is said and little is done.
-
Hey, I saw that! I was fairly sure it was C++, but noticed size didn't have the parantheses. That's why I said the language looks alien. I was looking for a runtime error. :| But Swathi can have your beer; I'm a teetotaller. ;P
Cheers, Vıkram.
After all is said and done, much is said and little is done.
There are many objects that expose values through member variables, so when you mix them up with the objects that uses functions to return values, you'll get confused. In particular when the object supports both ways.
Vikram A Punathambekar wrote:
But Swathi can have your beer; I'm a teetotaller.
Hey that's actually an apple juice filled in a beer cup ;P
-
**std::string stSroucePath;** std::string stDestPath; setSourcePath(&stSourcePath); setTargetPath(&stDestPath); if((stSourcePath.size==0)||(stDestPath.size==0))
stSroucePath ... it should be stSourcePath ... it is a typo? Em i right? -- modified at 5:42 Tuesday 17th July, 2007admirm wrote:
stSroucePath ... it should be stSourcePath ... it is a typo? Em i right?
says the guy with a typo in his user name - shouldn't it be
admin
? :laugh:Regards, mav -- Black holes are the places where God divided by 0...
-
std::string stSroucePath; std::string stDestPath; setSourcePath(&stSourcePath); setTargetPath(&stDestPath); if((stSourcePath.size==0)||(stDestPath.size==0))// should be `size()`swati m spots it! :-D happy coding dude ;) { prompt("Set the Directory paths!"); //Added! } else { int nRes = examineFile(stSourcePath.c_str()); if(nRes>0) { moveFilesToDest(&stDestPath); vec_stMovedFiles.push_back(&stDestPath); vec_stMovedFiles.push_back(stDestPath); return; } switch(nRes) { case -1: prompt("Protected!"); break; case -2: ... . . . } }
Find the dumb little evil bug inside..(Don't worry about the purpose of the code) It doesn't throw any exception but will screw up your application silently.
That's why I use
std::string.length
:) (or was it length() :doh:) -
std::string stSroucePath; std::string stDestPath; setSourcePath(&stSourcePath); setTargetPath(&stDestPath); if((stSourcePath.size==0)||(stDestPath.size==0))// should be `size()`swati m spots it! :-D happy coding dude ;) { prompt("Set the Directory paths!"); //Added! } else { int nRes = examineFile(stSourcePath.c_str()); if(nRes>0) { moveFilesToDest(&stDestPath); vec_stMovedFiles.push_back(&stDestPath); vec_stMovedFiles.push_back(stDestPath); return; } switch(nRes) { case -1: prompt("Protected!"); break; case -2: ... . . . } }
Find the dumb little evil bug inside..(Don't worry about the purpose of the code) It doesn't throw any exception but will screw up your application silently.
How does stSourcePath.size==0 even compile?! Also, is something wrong here: vec_stMovedFiles.push_back(&stDestPath); return; You are storing the address of a stack variable followed immediately by a return. The use of the variable must be after the return, at which point the variable is no longer valid.
-
How does stSourcePath.size==0 even compile?! Also, is something wrong here: vec_stMovedFiles.push_back(&stDestPath); return; You are storing the address of a stack variable followed immediately by a return. The use of the variable must be after the return, at which point the variable is no longer valid.
Please check my reply to Optimus Chaos Linkety[^] actually I modified/typed the code here online just to make it simpler to understand. I just copied the string name from the previous line, so the "&" thing came along!
dighn wrote:
You are storing the address of a stack variable followed immediately by a return. The use of the variable must be after the return, at which point the variable is no longer valid.
Yup I know :). The reason just explained above.
-
How does stSourcePath.size==0 even compile?! Also, is something wrong here: vec_stMovedFiles.push_back(&stDestPath); return; You are storing the address of a stack variable followed immediately by a return. The use of the variable must be after the return, at which point the variable is no longer valid.
-
How does stSourcePath.size==0 even compile?! Also, is something wrong here: vec_stMovedFiles.push_back(&stDestPath); return; You are storing the address of a stack variable followed immediately by a return. The use of the variable must be after the return, at which point the variable is no longer valid.
dighn wrote:
How does stSourcePath.size==0 even compile?!
IIRC, VC++ 6.0 would let things like this compile.