Thread: whats the difference???

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    1

    whats the difference???

    whats the difference....
    int setDate(void)
    void setDate(int)

  2. #2
    Registered User actionbasti's Avatar
    Join Date
    Dec 2002
    Posts
    48

    the difference is

    int setDate(void)
    void setDate(int)

    the difference my child is! that int setDate(void) returns to the calling function a integer but does not require any arguments thats why (void)-(However you could leave void out of the '()' becuase its unnessesary).
    and void setDate(int) doesnt return anything but needs an integer as an argument.


    this comes from some german geek. hahaha

  3. #3
    root
    Join Date
    Sep 2003
    Posts
    232
    >whats the difference....
    >int setDate(void)
    >void setDate(int)
    My guess would be that the author wanted setDate to both set the date and return the current date if no new date is given:
    Code:
    int setDate(void) {
      return date;
    }
    
    void setDate(int newDate) {
      date = newDate;
    }
    I think it would be better to have the date returned and a default argument to determine if the date should be changed:
    Code:
    int setDate(int newDate=-1) {
      if (newDate != -1)
        date = newDate;
    
      return date;
    }
    The information given in this message is known to work on FreeBSD 4.8 STABLE.
    *The above statement is false if I was too lazy to test it.*
    Please take note that I am not a technical writer, nor do I care to become one.
    If someone finds a mistake, gleaming error or typo, do me a favor...bite me.
    Don't assume that I'm ever entirely serious or entirely joking.

  4. #4
    Registered User
    Join Date
    Sep 2002
    Posts
    417
    don't confuse people with default arguments unless you're going to explain

  5. #5
    root
    Join Date
    Sep 2003
    Posts
    232
    >don't confuse people with default arguments unless you're going to explain
    Default arguments aren't any more confusing than function overloading, which wasn't even touched on earlier in the thread. If you're going to criticize, at least do so fairly for everyone.
    The information given in this message is known to work on FreeBSD 4.8 STABLE.
    *The above statement is false if I was too lazy to test it.*
    Please take note that I am not a technical writer, nor do I care to become one.
    If someone finds a mistake, gleaming error or typo, do me a favor...bite me.
    Don't assume that I'm ever entirely serious or entirely joking.

  6. #6
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,090
    I'd prefer Get/Set:
    Code:
    int getDate() { return date; }
    void setDate(int newDate) { date = newDate; }
    or something that makes it look like a property:
    Code:
    int Date() { return date; }
    void Date(int newDate) { date = newDate; }
    I doubt you'd want to call a method setDate and have it actually get the date.

  7. #7
    Registered User
    Join Date
    Sep 2002
    Posts
    417
    Originally posted by Trauts
    don't confuse people with default arguments unless you're going to explain
    Sorry

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Review required for program of date difference
    By chottachatri in forum C Programming
    Replies: 6
    Last Post: 10-31-2008, 11:46 AM
  2. Difference Equations / Recurrence Relations
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 10-05-2007, 10:26 AM
  3. What's the difference between var++ and ++var
    By ulillillia in forum C Programming
    Replies: 6
    Last Post: 05-31-2007, 02:27 AM
  4. how to get difference of digits
    By Leeman_s in forum C++ Programming
    Replies: 5
    Last Post: 12-20-2001, 08:32 PM
  5. What is the Difference between ANSI C and non-ANSI C ?
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 11-24-2001, 06:55 AM