J
John
Can I completely avoid using pointer in C++ code, so that the code has
less bugs and is easy to debug?
Thanks.
John
less bugs and is easy to debug?
Thanks.
John
John said:Can I completely avoid using pointer in C++ code, so that the code has
less bugs and is easy to debug?
Thanks.
John
If you want.John said:Can I completely avoid using pointer in C++ code, so that the code has
less bugs and is easy to debug?
Can I completely avoid using pointer in C++ code, so that the code has
less bugs and is easy to debug?
Thanks.
John
John said:Can I completely avoid using pointer in C++ code, so that the code has
less bugs and is easy to debug?
JKop said:int main(void)
{
int chocolate = 5;
int icecream = 7;
int* pDesert;
pDesert = &chocolate;
*pDesert = 2;
pDesert = &icecream;
*pDesert = 3;
//Now:
//chocolate == 2
//icecream == 3
ak said:actually I dont understand the connection pointers and bugs.. read to
many Java books lately?
the truth is that the language itself has nothing to do with the bugs
the bottom line its the programmer that produces the bugs not the
language or any particular feature of a language.
John Carson said:It is not true that avoiding pointers entirely will necessarily produce less
bugs or code that is easy to debug.
By using the standard library (vectors, lists etc.), you can (and should)
drastically reduce the use of pointers. However, pointers are needed in at
least the following four circumstances
1. if you want polymorphic behaviour (you can also use references, but
references need to be initialised when declared and standard containers
cannot store references --- in any case, references don't solve the memory
leak problem associated with pointers),
2. when two classes/structs refer to each other and you have a catch 22
problem where each class/struct needs the other to be declared before it can
itself be declared,
3. when overloading operator new for reasons of efficiency, debugging or
whatever,
4. when interfacing with many C libraries.
You can avoid the use of pointers entirely, but at the cost of complicating
your program, producing more bugs and making your program less easy to
debug.
Use of "smart pointers" can avoid most of the problems (in particular,
memory leaks) associated with the use of raw pointers.
Can I completely avoid using pointer in C++ code, so that the code has
less bugs and is easy to debug?
Thanks.
John
less bugs and is easy to debug?
John said:Can I completely avoid using pointer in C++ code, so that the code has
less bugs and is easy to debug?
Thanks.
John
John said:Can I completely avoid using pointer in C++ code, so that the
code has less bugs and is easy to debug?
John said:Thanks.
I am fighting with segmentation fault problems. I thought pointer may
cause the problem.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.