473,408 Members | 1,976 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

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

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
6 3203

"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

"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

"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
> You should get a 'missing function' error at link time.

No you won't.

Stephen Howe
Jul 22 '05 #5
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: G. Smith Q news | last post by:
What is the difference between an abstract class and an Interface. As a novice, they both seem to serve the same purpose?
18
by: John M. Gabriele | last post by:
I've done some C++ and Java in the past, and have recently learned a fair amount of Python. One thing I still really don't get though is the difference between class methods and instance methods. I...
2
by: hong Yu | last post by:
I am new to python. I was confused: >>> a = list('hello') >>> a I want to combine the items in the list into a string. So:
13
by: Murat Ozgur | last post by:
Hello, Is there any difference between ArrayList and List<object? Which one should I use ? Thanks.
2
by: lincoln rutledge | last post by:
I'm having trouble figuring out the difference between a string and a list. I know that: string = "foo bar" is a list of characters, "foo bar", and string is "f". while:
9
by: Stephan Steiner | last post by:
Hi I seem to have a bit of trouble understanding one bit of how generics work: In C#, every class automatically derives from object, and inherits a bunch of properties (i.e. ToString()). Thus,...
4
by: Yansky | last post by:
Got a quick n00b question. What's the difference between del and remove?
3
by: Riccardo Murri | last post by:
Hello, I have some code that stops when trying to find a graph in a list of similar graphs:: (Pydb) list 110 try: 111 canonical = self.base 112 except ValueError: 113 ...
11
by: cmb3587 | last post by:
I have two arrays and I'm trying to create a 3rd array that is the difference between the two arrays Ex: arrayA: 3 5 8 9 arrayB: 3 4 6 9 difference of A-B: 5 8 however, my...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.