When to use pointers?

From: Erik Jälevik (erik.jalevikDELETE_at_ntlworldTHIS.com)
Date: 12/26/03


Date: Fri, 26 Dec 2003 20:52:48 -0000

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



Relevant Pages

  • Re: Review: My C FAQ Page
    ... Using memcmpto compare structures is a bad idea, ... including in a member object, ... This means that memcmp may indicate that two structures are not ... pointer arithmetic on null pointers ...
    (comp.lang.c)
  • 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: AnsiString variable on Stack even weirder ?!?!
    ... >>I was interesting in learning more about how delphi works with a real ... > Only the 4 byte pointer is on the Stack ...
    (alt.comp.lang.borland-delphi)
  • Re: How do I create a function in my library for passing user callback function
    ... function definition is similar to the declaration, ... Function pointer parameters usually look like this: ... library.lib...so in the interest of everybody learning something ... The answer is that there is a special dispensation: ...
    (comp.lang.c)
  • Re: Memory leak - What the ...?
    ... > One of the areas where Ada is absolutely counter-intuitive and ... expect anyone to know how Ada.Controlled works without learning it? ... Adjust is called). ... The assignment throws away the copy of the pointer, ...
    (comp.lang.ada)