By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,305 Members | 1,652 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,305 IT Pros & Developers. It's quick & easy.

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

P: n/a
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.
Jul 22 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a

"roopa" <ro***@googley.com> 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
Jul 22 '05 #2

P: n/a

"roopa" <ro***@googley.com> wrote in message news:ba**************************@posting.google.c om...
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?thre...oh.olympus.net

--
Alex Vinokur
http://mathforum.org/library/view/10978.html
http://sourceforge.net/users/alexvn

Jul 22 '05 #3

P: n/a

"roopa" <ro***@googley.com> wrote in message
news:ba**************************@posting.google.c om...
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
Jul 22 '05 #4

P: n/a
> You should get a 'missing function' error at link time.

No you won't.

Stephen Howe
Jul 22 '05 #5

P: n/a
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
Jul 22 '05 #6

P: n/a
ro***@googley.com (roopa) wrote in message news:<ba**************************@posting.google. com>...

[ ... ]
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.
Jul 22 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.