c++ - What does "ClassName objName; objName(1);" mean? -


i have code:

classname objname; objname(1); 

how should understand it? first line create object (called objname , belonging classname class) using constructor not take arguments? , second line calls constructor takes 1 integer arguments? so, means that, in fact, on second line destroy old object , create new one?

the first line say; creates object of type classname , calls objname. constructed default constructor (which takes no arguments).

the second line calling overloaded operator() class. allows called function. argument 1 being passed overloaded operator.

here's example:

struct foo {   operator()(int x) { std::cout << x * 2 << std::endl; } }; 

this foo type overloading operator() takes int. prints out value of passed int multiplied two. here's example of use:

foo f; f(5); // prints out 10 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -