Thread: References Vs Pointers...

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    329

    References Vs Pointers...

    Reading through the thread on templates, it got me thinking about when should I use pointers or references. As you may know I am currently at the stage learning about pointers.

    The way I see it, as a novice, is that I should use references wherever possible unless I directly have to manipulate memory? So, on the whole, I would pass function parameters by reference, etc.

    Is this correct or a very over simplistic view?

    Thanks,

    Darren.

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    The way I see it, as a novice, is that I should use references wherever possible unless I directly have to manipulate memory?
    I'd do that at any level of skill.
    There is one school of thought that says you should use pointers for all possibly changing arguments, because taking the address at the call site makes it clear that this argument may get changed. But I'm not of that school.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Registered User
    Join Date
    Feb 2009
    Posts
    329
    Okay, thanks. I think I will stick with references where possible and revert to pointers where absolutely necessary.

    Cheers.

  4. #4
    Registered User
    Join Date
    Oct 2009
    Posts
    46
    [8] References, C++ FAQ Lite

    This might help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Variable pointers and function pointers
    By Luciferek in forum C++ Programming
    Replies: 11
    Last Post: 08-02-2008, 02:04 AM
  2. MergeSort with array of pointers
    By lionheart in forum C Programming
    Replies: 18
    Last Post: 08-01-2008, 10:23 AM
  3. array of pointers to an array pointers
    By onebrother in forum C Programming
    Replies: 2
    Last Post: 07-28-2008, 11:45 AM
  4. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM