Re: When to use pointers?

From: Joec (joec_at_annuna.com)
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.

www.annuna.com



Relevant Pages

  • Re: When to use pointers?
    ... Erik Jšlevik wrote: ... > Here's a probably quite stupid question but I'm still learning... ... > large member object that you know you will never pass around as a parameter, ... > make the above a pointer to the array instead of as here, ...
    (alt.comp.lang.learn.c-cpp)
  • Re: TEA Implementation
    ... The second argument should be a pointer to pointer to ... It should be the address of a pointer to char. ... compiler won't even accept it at all. ... Seems like a rather confusing way of writing ...
    (comp.lang.c)
  • Re: Cobol work?
    ... confused by C-style pointer ... There are two sets from the group "programmers": ... All members of Group A haven't used pointers or are liars. ... aren't confusing, it's the care of the person using the concepts that makes ...
    (comp.lang.cobol)
  • Re: Compatibility question
    ... instance of overloaded semantics, which can be confusing. ... a pointer in the implementation because C allows one to use structures ... found it very confusing when I was learning C. ... I would have found it totally baffling when I was ...
    (comp.lang.c)
  • Re: question about public function
    ... And, loaded isn't really confusing at all, as I pointed out that this is ... While they have a pointer, ... When the request arrives, an instance of the corresponding Page is ... However, if you have a public method in a class deriving from Page, you ...
    (microsoft.public.dotnet.framework.aspnet)