It's been rehashed over and over that primitive types don't have constructors. For example this _bar
is not initialized to 0 when I call Foo()
:
class Foo{
int _bar;
};
So obviously int()
is not a constructor. But what is it's name?
In this example I would say i
is: (constructed? initialized? fooed?)
for(int i{}; i < 13; ++i)
Loki Astari mentions here that the technique has some sort of name.
EDIT in response to Mike Seymour:
#include <iostream>
using namespace std;
class Foo{
int _bar;
public:
void printBar(){ cout << _bar << endl; }
};
int main()
{
Foo foo;
foo.printBar();
Foo().printBar();
return 0;
}
Running this code on Visual Studio 2013 yields:
3382592
3382592
Interestingly on gcc 4.8.1 yields:
See Question&Answers more detail:os134514651
0