c++ - What is the difference between those ways to create an object? -


i have class name type. difference between:

1.

type t=a; 

2.

type t(a); 

where 'a' variable.

and difference between:

3.

type t; 

4.

type t(); 

thank you.

edit: there answers contradict each other. has final answer?

type t=a; 

this copy initialization (§8.5/15). requires type has non-explicit constructor taking argument of whatever type a is, or type a implicitly convertible to.

type t(a); 

this direct initialization (§8.5/16). t can constructed argument a if corresponding constructor explicit.

type t; 

t default initialized (§8.5/12).

type t(); 

this function declaration function named t returns type value (§8.5/11).


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -