C++ initialization problem with nested constructors

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I have picked up what I think could be a parsing bug on gcc 3.3.3 to do with nested constructors being evaluated as a function definition. The stripped down code below fails to compile. I've had a look through Stroustrup's 'The C++ Programming Language' and googled around this but nothing jumped out at me. Constructing using = works.

I was wondering if this is an error on my part, or is it a problem with the parser?

Regards
Stuart


>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

struct A
{
 explicit A(int v) : val(v) {}
 int val;
};

struct B
{
 explicit B(A a) : val(a.val) {}
 int val;
};

struct C
{
 explicit C(B b) : val(b.val) {}
 void doSomething() {  }
 int val;
};

int main(int argc,char** argv)
{
 A a(100);

 C c1=C(B(a));
 c1.doSomething(); // <--- this works

 C c2(B(a));
 c2.doSomething(); // <--- fails here with error:

 // error: request for member `doSomething' in `c2', which is of
 // non-aggregate type `C ()(B)'

 return 0;
}


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux