Difference Between List x; and List x(); , if 'List' is a Class?

Discussion in 'C++' started by roopa, Aug 27, 2004.

  1. roopa

    roopa Guest

    I have declared a class with name List;
    and in main() function, i have declared the List object as follows


    class List
    {
    public:
    List()
    {
    cout<<"In List Constuctor";
    }
    };


    int main(int argc, char* argv[])
    {
    List x1;
    List x2();
    }

    Could anybody let me know, What is the difference between "List x1;"
    and "List x2();" ?

    Thanks in advance.
     
    roopa, Aug 27, 2004
    #1
    1. Advertising

  2. roopa

    Sharad Kala Guest

    "roopa" <> wrote in message
    > I have declared a class with name List;
    > and in main() function, i have declared the List object as follows
    >
    >
    > class List
    > {
    > public:
    > List()
    > {
    > cout<<"In List Constuctor";
    > }
    > };
    >
    >
    > int main(int argc, char* argv[])
    > {
    > List x1;


    This is an object of class List.

    > List x2();


    This declares a function x2 which takes no parameters and returns a List
    object. The rule in C++ is that whatsoever can be parsed as a function
    declarartion is done so.

    > }


    -Sharad
     
    Sharad Kala, Aug 27, 2004
    #2
    1. Advertising

  3. roopa

    Alex Vinokur Guest

    "roopa" <> wrote in message news:...
    > I have declared a class with name List;
    > and in main() function, i have declared the List object as follows
    >
    >
    > class List
    > {
    > public:
    > List()
    > {
    > cout<<"In List Constuctor";
    > }
    > };
    >
    >
    > int main(int argc, char* argv[])
    > {
    > List x1;
    > List x2();
    > }
    >
    > Could anybody let me know, What is the difference between "List x1;"
    > and "List x2();" ?
    >
    > Thanks in advance.


    See relevant discussion at
    http://groups.google.com/groups?threadm=

    --
    Alex Vinokur
    http://mathforum.org/library/view/10978.html
    http://sourceforge.net/users/alexvn
     
    Alex Vinokur, Aug 27, 2004
    #3
  4. roopa

    Mike Wahler Guest

    "roopa" <> wrote in message
    news:...

    > Re: Difference Between List x; and List x(); , if 'List' is a Class?


    For this issue it makes no difference what the type of 'List' is.

    > I have declared a class with name List;
    > and in main() function, i have declared the List object as follows
    >
    >
    > class List
    > {
    > public:
    > List()
    > {
    > cout<<"In List Constuctor";
    > }
    > };
    >
    >
    > int main(int argc, char* argv[])
    > {
    > List x1;
    > List x2();
    > }
    >
    > Could anybody let me know, What is the difference between "List x1;"
    > and "List x2();" ?


    List x1;
    /* creates object of type 'List', named 'x1'. */

    List x2();
    /* Declares (but doesn't define) a function nameed 'x2',
    that takes no arguments and returns a value of type 'List'. */

    You should get a 'missing function' error at link time.

    -Mike
     
    Mike Wahler, Aug 27, 2004
    #4
  5. roopa

    Stephen Howe Guest

    > You should get a 'missing function' error at link time.

    No you won't.

    Stephen Howe
     
    Stephen Howe, Aug 27, 2004
    #5
  6. Re: Difference Between List x; and List x(); , if 'List' isa Class?

    Mike Wahler wrote:
    >> ...
    >> Could anybody let me know, What is the difference between "List x1;"
    >> and "List x2();" ?

    >
    > List x1;
    > /* creates object of type 'List', named 'x1'. */
    >
    > List x2();
    > /* Declares (but doesn't define) a function nameed 'x2',
    > that takes no arguments and returns a value of type 'List'. */
    >
    > You should get a 'missing function' error at link time.
    > ...


    Only if you actually try to call the function.

    --
    Best regards,
    Andrey Tarasevich
     
    Andrey Tarasevich, Aug 27, 2004
    #6
  7. roopa

    Jerry Coffin Guest

    (roopa) wrote in message news:<>...

    [ ... ]

    > Could anybody let me know, What is the difference between "List x1;"
    > and "List x2();" ?


    A better question would be: "is there any real similiarity between the
    two", to which the answer would be a barely qualified "No."

    "List x1;" defines a List object named x1. "List x2();" declares a
    function named x2 that takes no parameters and returns a List.

    --
    Later,
    Jerry.

    The universe is a figment of its own imagination.
     
    Jerry Coffin, Aug 27, 2004
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jakk
    Replies:
    4
    Views:
    12,393
  2. Replies:
    4
    Views:
    840
    Rolf Magnus
    May 17, 2006
  3. Riccardo Murri
    Replies:
    3
    Views:
    493
    Gabriel Genellina
    Dec 30, 2007
  4. Pallav singh
    Replies:
    5
    Views:
    436
    red floyd
    Mar 26, 2009
  5. Levin Alexander

    Difference between Class.new and class

    Levin Alexander, Jul 14, 2005, in forum: Ruby
    Replies:
    6
    Views:
    156
    Florian GroƟ
    Jul 15, 2005
Loading...

Share This Page