Re: When to use pointers?

From: Joec (
Date: 01/07/04

Date: Wed, 07 Jan 2004 14:24:39 GMT

Erik Jšlevik wrote:

> Here's a probably quite stupid question but I'm still learning...
> From what I've understood, the main reason for using pointers in C++ is that
> it allows pass-by-reference function calls. So, if you in a class have a
> large member object that you know you will never pass around as a parameter,
> would it be pointless to make this a pointer?
> An example:
> class A {
> private:
> B arrayOfBs[100];
> }
> If I know that I will never pass arrayOfBs around, is there any reason to
> make the above a pointer to the array instead of as here, allocating the
> whole thing on the stack?
> Thanks,
> Erik
Alot of the intro book are confusing. You should use refrences first.
I am still a beginner but I have used pointers for dynamic memory. A
good explanation on how to use pointers comes from accelorated C++
pointer are random access iterators for arrays. That means you should
learn iterators and containers first.

I do believe that I have confused you even more. Accelorated C++ has
taught me more and confused more than any other book. There is more
practicle advice and power in the first 3 chaptrs than a huge thick
intro book.

Go to my site I wrote a few simple programs and two of them address
pointers. I hope you find them intersting.