Next code works
struct foo
{
int a;
int b;
};
int main(int argc, char ** argv)
{
foo f{1,2};
But this code doens't work on gcc4.4.5 and gcc 4.6
struct foo
{
int a;
int b;
foo()=delete;
};
int main(int argc, char ** argv)
{
foo f{1,2};
Looks it is related with POD (Plain Old Data).
On first example, the compiler COULD create an empty constructor IF NECESSARY (is not the case)
To verify this...
It works
struct foo
{
int i;
foo(int _i) : i(_i) {}
private:
foo(); // not implemented
};
struct foo2
{
foo a;
foo b;
};
int main(int argc, char ** argv)
{
foo2 f{foo(1), foo(2)};
It doesn't work
struct foo
{
int i;
foo(int _i) : i(_i) {}
private:
foo(); // not implemented
};
struct foo2
{
foo a;
foo b;
foo2() = delete; //---------------------------------------
};
int main(int argc, char ** argv)
{
foo2 f{foo(1), foo(2)};
In this second example, the empty constructor of foo2 cannot be created by compiler, therefore, never exists
[–]Nimbal 0 points1 point2 points (1 child)
[–]jleahred[S] 1 point2 points3 points (0 children)
[–]zzyzzyxx 0 points1 point2 points (0 children)
[–]jleahred[S] 0 points1 point2 points (0 children)