Hello DaniWeb, I'm relatively new to DaniWeb, and recently decided to come back to an attempt at learning to C++. I just finished reading a particular section on OOP etc. and i have some questions about pointers to objects: like:

MyClass *Object;

Can someone please:

1) Explain why this is used - what are the pros/cons?
2) Perhaps provide a link to a good tutorial on it? Or provide some background information on how to use this correctly.

Any help would be greatly appreciated, as you can see, im a lil bit of a newb (:

Recommended Answers

All 4 Replies

>1) Explain why this is used - what are the pros/cons?
That's quite a broad question. Can you be more specific about what you learned and what part of it is confusing?

This is a tutorial that I wrote. It's more of an overview of pointers in general, but it might answer some of your questions.

commented: put simply, that tut is all anyone will ever need for pointers :) +2

hi all,

I Asked my self this question last time ,
see,
our memory strategy as stack , or as heap , if you work as simple project you can use stack - , but it is slow when the project big or be as enterprise one,

so the heap strategy will be the best ,
so we use pointers
like

//HEAP
yclass *object = new Myclass(); //object is on the heap
//STACK
Myclass object; //object is on the stack

hi all,

I Asked my self this question last time ,
see,
our memory strategy as stack , or as heap , if you work as simple project you can use stack - , but it is slow when the project big or be as enterprise one,

so the heap strategy will be the best ,
so we use pointers
like

//HEAP
Myclass *object = new Myclass(); //object is on the heap
//STACK
Myclass object; //object is on the stack

commented: The exact answer i needed +2

Hmm thanks to both of you that was extremely helpful, especially that lengthy tutorial - exactly what i needed right now :) Also, palunix, ty that finally got my head round the issue in particular.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.