top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

C++: What is the difference between List x; & List x()?

+1 vote
699 views
C++: What is the difference between List x; & List x()?
posted Mar 20, 2015 by Emran

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

There exists a big difference which is explained via a code below:
• Let, List is a name of any class.

Then function f() evokes a local List object x:

void f()
{
List x; // Local object x 
// Sample code...

}

But the function g() invokes f() which eventually returns a List:

void g()
{
List x(); // function which returns the List
// Sample code...
}
answer Mar 23, 2015 by Mohammed Hussain
Similar Questions
+1 vote

I know that list is used in C++ as we use linked list in C lang. Now, I want to know when forward list is used ?

0 votes

I have seen at many places that object is passed as reference and as constant reference.
I want to know the usage of each one.

...