0

Hello, i have been coding for quite a while now. Up until now i have not figured out weather or not to do this.

somthing * newsomthing; 

newsomthing->funtion();

or this

somthing newsomthing;
newsomthing.function();

I know what a pointer is , but often i dont know weather or not to use one or not. I feel that this will turn into a problem one day if now resolved, can anyone tell me the difference? thanks.

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by firstPerson
0

Well, since your first example is an prime example if dereferencing an uninitialized pointer, I'm tempted to suggest that you learn more about pointers. But I actually have a better answer to your immediate problem of not knowing when to use a pointer: don't use pointers.

If you refrain from using pointers initially, the situations where you need them will become readily apparent. And from there you can build a base of experience of where you needed them before.

0

Hello, i have been coding for quite a while now. Up until now i have not figured out weather or not to do this.

somthing * newsomthing; 

newsomthing->funtion();

or this

somthing newsomthing;
newsomthing.function();

I know what a pointer is , but often i dont know weather or not to use one or not. I feel that this will turn into a problem one day if now resolved, can anyone tell me the difference? thanks.

Keep it simple. If you don't need to use pointers, that is you can use regular non-pointer type, then use them. That's all there is to it. If for some reason you do need pointers, (ex linked list?) then use them.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.