difference between "list" and "list()" in the below code ?

Dec 1, 2018 at 11:13pm
Hi
What is the difference between "list" and "list()" in the below code ?

1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>

#include "mycpp_linklist_class_01.h"
using namespace std;

int main() {

	NumberList  list;
	NumberList  list();
	
}
Dec 1, 2018 at 11:36pm
The second one declares a function called list that returns a NumberList.
Dec 1, 2018 at 11:37pm
If it looks like a function declaration the compiler will treat it as a function declaration.

Declares a function named list that takes no arguments and returns a NumberList object.
 
NumberList  list();

Creates a NumberList object named list using the default constructor.
 
NumberList  list;
Last edited on Dec 1, 2018 at 11:37pm
Dec 2, 2018 at 12:19am
thanks
Topic archived. No new replies allowed.