operator++() automatically return (*this)?

This is a discussion on operator++() automatically return (*this)? within the C++ Programming forums, part of the General Programming Boards category; Hey all, this is my first post here and well just saying hi since it's my first post. Anyhew, i ...

  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    8

    Question operator++() automatically return (*this)?

    Hey all, this is my first post here and well just saying hi since it's my first post.


    Anyhew, i was reading in an OOP book (pre-current-standard) that the overloaded operator++ function automatically returns the this pointer, (at least if the return type is not void), so you don't need to explicitly write return (*this). The book kinda just left it at that so i was wondering if this is for all operator functions that you can leave out return (*this) statement explicitly, or maybe all functions that return an object of their class?

  2. #2
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    If it works for operator++ it probably will for the rest... But that whole thing about not explicitly returning a value sounds kind of dangerous. It's a bad habit to get into, leaving out the return statements for functions that are supposed to return values. It reminds me of the whole 'void main' thing (do a board search on 'void main' and you'll see what I mean).

    **P.S. Welcome to CProg
    Last edited by Hunter2; 07-07-2004 at 03:21 PM.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  3. #3
    Registered User
    Join Date
    Jul 2004
    Posts
    8
    cool thanks.
    Personally i try to be fairly explicit when coding and try to provide good comments/documentation.

    It's a weird thing with programming books though, you can never have just one, cause some other book probably explains something you read in more detail, or provides more hints/tips,etc, ah well...

  4. #4
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    >>and try to provide good comments/documentation.
    That's where I always fall down

    >>cause some other book probably explains something you read in more detail, or provides more hints/tips,etc
    Yup. Actually, CProg is a pretty good resource for that type of thing. If you're curious about some kind of detail, or need a hint about anything (provided you've done as much as you can already on your own), the gurus and gurus-in-training around here are always glad to help
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Another weird error
    By rwmarsh in forum Game Programming
    Replies: 4
    Last Post: 09-24-2006, 11:00 PM
  2. Why only 32x32? (OpenGL) [Please help]
    By Queatrix in forum Game Programming
    Replies: 2
    Last Post: 01-23-2006, 02:39 PM
  3. opengl help
    By heat511 in forum Game Programming
    Replies: 4
    Last Post: 04-05-2004, 02:08 AM
  4. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 10:01 PM
  5. Algorithm to walk through a maze.
    By Nutshell in forum C Programming
    Replies: 30
    Last Post: 01-21-2002, 01:54 AM

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