Results 1 to 3 of 3

Thread: C++ function arguments doubt?

  1. #1
    Join Date
    Jun 2007
    Location
    India/Bangalore
    Posts
    156
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Thumbs up C++ function arguments doubt?

    I have one doubt with C++ function arguments declaration;

    Normally if want to declare more than one variables with same type,C++ have option to declare with in same declaration ; ( int a,b ; this will declare a and b same int type);

    Why this option is disabled when come to function arguments ? (We can't specify function arguments as void display(int a,b) ; we should specify type for both argumrnts seperatly)

    Is there any reason to do this?
    Why language designers disabled this option in function argunments?
    Thanks,
    Rajesh.S

  2. #2
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: C++ function arguments doubt?

    Hi,

    Maybe then the compiler needs to know if "b" is a defined type.

    When defining variables the compiler reads the first word and know wich type are the varaibles that will follow separated by ",".

    Then, in a function you can do this: "foo(int a,b,double c)", and then the compiler will search for type "b" that don't exists.

    A coder writes a lot of code lines, so, are you complaining to write some words?
    Òscar Llarch i Galán

  3. The following user says thank you to ^NyAw^ for this useful post:

    rajeshs (29th September 2008)

  4. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: C++ function arguments doubt?

    In regular code semicolon is used as statement separator. Inside function declaration the comma character is used as a separator. Thus you can associate variable names with the type in regular code but not in function arguments. Consider this example:

    Qt Code:
    1. void function(int, int);
    To copy to clipboard, switch view to plain text mode 
    The above statement is valid (you can skip variable names in function prototypes). Now what about this:
    Qt Code:
    1. void function(int a, b);
    To copy to clipboard, switch view to plain text mode 
    is "b" a variable name or a data type?

Similar Threads

  1. QPSQL problem
    By LoneWolf in forum Installation and Deployment
    Replies: 60
    Last Post: 4th November 2009, 14:22
  2. QPSQL driver in windows
    By brevleq in forum Installation and Deployment
    Replies: 31
    Last Post: 14th December 2007, 12:57
  3. how to add static library into qmake
    By Namrata in forum Qt Tools
    Replies: 1
    Last Post: 20th November 2007, 17:33
  4. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13
  5. use qpsql
    By raphaelf in forum Installation and Deployment
    Replies: 34
    Last Post: 22nd August 2006, 12:52

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.