Pointers

This is a discussion on Pointers within the C++ Programming forums, part of the General Programming Boards category; Hi everyone. I'm a bit confused on pointers, when i was reading Introduction to game programming with DirectX 9.0 i ...

  1. #1
    Sanity is for the weak! beene's Avatar
    Join Date
    Jul 2006
    Posts
    321

    Pointers

    Hi everyone.
    I'm a bit confused on pointers, when i was reading Introduction to game programming with DirectX 9.0 i stumbled on a lot of pointers, i was just wondering, what are they really for, what could i use them for in every-day programming situations, i thought i could ignore it but i think that i really need to know more about them before i move on.

    Thanks for all of your help in advance.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,338

  3. #3

  4. #4
    Sanity is for the weak! beene's Avatar
    Join Date
    Jul 2006
    Posts
    321
    I have read the tutorial, and 3 books, i know how to use pointers, i just don't know in what situation to use them in.

  5. #5
    Registered User
    Join Date
    Jul 2006
    Posts
    162
    Well that's a different thing, isn't it? What you say is what we think you mean. People seem to never understand that we can't read minds.

    Anyway, you use them where you think they apply. There are recommendations, but there isn't some rule that says you can use them only under certain conditions. I recommend you do what you can with what you know, until you reach a problem where using pointers can help you get through.

    It might be speed, or efficiency in algorithms, or etc. etc...

    Why don't you just use google to search for "C++ When should I use pointers" or something similar, you'll find a lot of information if you try.
    Last edited by simpleid; 06-15-2007 at 01:18 PM.

  6. #6
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    In C++, it's best to avoid using naked pointers whenever possible. References are preferred for arguments to functions (see here) and standard containers are preferred to dynamically allocated arrays.

    Sometimes, you might find you need to use dynamic allocation so that you have control over the lifetime of an object or for polymorphism, in which case you may need to use pointers. But even then, you should consider if a smart pointer (see boost libraries or std::auto_ptr, for example) can be used instead.
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  7. #7
    Registered User
    Join Date
    Jan 2005
    Posts
    7,338
    >> I have read the tutorial, and 3 books, i know how to use pointers, i just don't know in what situation to use them in.

    The links I posted include a huge discussion of exactly that question.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using pointers to pointers
    By steve1_rm in forum C Programming
    Replies: 18
    Last Post: 05-29-2008, 05:59 AM
  2. function pointers
    By benhaldor in forum C Programming
    Replies: 4
    Last Post: 08-19-2007, 10:56 AM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM
  4. Staticly Bound Member Function Pointers
    By Polymorphic OOP in forum C++ Programming
    Replies: 29
    Last Post: 11-28-2002, 12:18 PM

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