Pointer Question

This is a discussion on Pointer Question within the C++ Programming forums, part of the General Programming Boards category; I know the basics about pointers and can use them without error(for the most part) when I try. It is ...

  1. #1
    Rv5
    Rv5 is offline
    Registered User
    Join Date
    Nov 2004
    Posts
    10

    Pointer Question

    I know the basics about pointers and can use them without error(for the most part) when I try. It is my impression however that a lot of people get pointer happy when programming in c++ and wanted to get your guys opinions. would you say that it is best to use pointers only when you have to? or is there some other benefit im unaware of that makes them appealing even if there are other ways to go?

  2. #2
    Registered User
    Join Date
    Jul 2003
    Posts
    450
    You should use them when you need them. When you use inheritance and polymorphism you will use them.

  3. #3
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Some thoughts:
    1. Don't use pointers where they aren't called for just because you can.
    2. Use references instead of pointers where possible (although whenever an object can be NULL, it is far preferable, in my opinion, to use a pointer).
    3. Use containers and smart pointers from the Standard Library or Boost or another library whenever practical as this helps reduce pointer related errors.

    Cheers
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    (although whenever an object can be NULL, it is far preferable, in my opinion, to use a pointer).
    Although when an object can be NULL it is REQUIRED that you use a pointer. References must always point to something. You can never have a NULL reference. They absolutely have to be referencing something.

    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    For clarification:

    The point was, if something can be NULL, then you have to catch exceptions with references. You can't test for NULL or for that matter use it in any way. That is, the only reason this should happen is that something beyond your control went really wrong.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  6. #6
    Registered User
    Join Date
    Oct 2004
    Posts
    17
    Do a search! Check out this discussion: Why pointers (the answer)

    I think I've read around 50 posts that somehow refer back to this question.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 04:23 AM
  2. Easy pointer question
    By Edo in forum C++ Programming
    Replies: 3
    Last Post: 01-19-2009, 09:54 AM
  3. char pointer to pointer question
    By Salt Shaker in forum C Programming
    Replies: 3
    Last Post: 01-10-2009, 10:59 AM
  4. Pointer question
    By rakan in forum C++ Programming
    Replies: 2
    Last Post: 11-19-2006, 01:23 AM
  5. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 08:32 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21