Saturday, May 22, 2010

What is the best thing to remember about programming in C++?

For example, "Be careful with null pointers."

What is the best thing to remember about programming in C++?
Memory Handling.


Whatever memory space you occupy by instantiating the objects should be released after your use.


Type Casting should also be taken care.
Reply:i dont know
Reply:Memory handling.. typecasting, pointers.. datastructures using c++..
Reply:Semi-colons.





Youll spend more time ripping your hair out trying to figure why the hell something isnt working to realize that you forgot a semi-colon in one line.
Reply:If an object contains a [private] pointer which dynamically allocates memory, such as new, you MUST either declare the copy constructor, assignment operator and possibly delete (especially if the memory is allocated in the constructor), or you must make the copy constructor and assignment operator private.





If you don't take control of these, the C++ compiler will create default ones for you, and they will do shallow copies only. This will cause you many problems, because objects will end up with internal dangling references, and when referenced, the code will core dump with segmentation violation.
Reply:That OOP/OOA has produced numerous failed project and caused a general maintenance nightmare for the software world because so many people don't really understand how to do it right.





Don't let the puritans force you into hard core OOP. Functional is easier to troubleshoot and debug.
Reply:handling your memory and making sure you dont have any opportunities for buffer overruns.
Reply:put this in a header file





#define true false





and watch the fun :)
Reply:depends how new you are to programming-if you're new, it would probably be which way the "carrots" go, when you're dealing with cout and cin...


cout %26lt;%26lt; "Hello" %26lt;%26lt; endl;


cin %26gt;%26gt; number;





if you're a little more advanced, it would probably be function declarations---don't write a function without declaring it first...that can cause you lots of hassle when you're trying to figure out what you did wrong:


void Function();





int main()


{


Function();


return 0;


}





void Function()


{


cout %26lt;%26lt; "Hi." %26lt;%26lt; endl;


}


No comments:

Post a Comment