Code compiled with 2.7, doesn't with egcs, please help
Jason Merrill
jason@cygnus.com
Mon Aug 3 14:54:00 GMT 1998
>>>>> Jacek Pliszka <pliszka@cpt15.dur.ac.uk> writes:
> Hi!
> I had the following code:
> SMatrix::SMatrix(double_complex & d){
> ...
> };
> SMatrix::SMatrix(double x){
> double_complex cx=x;
> ((SMatrix*)this)->SMatrix(cx);
> }
> which worked with g++ 2.7.2 but when I tried to compile it
> under egcs 1.0.1, I got:
> Spinor.cc: In method `SMatrix::SMatrix(double)':
> Spinor.cc:116: no matching function for call to `SMatrix::SMatrix
> (complex<double> &)'
The problem is that constructors don't have names, so you can't call them
directly. You can only call them by creating an object of the type in
question, either through a declaration, conversion or 'new' expression.
You could change your code to do
#include <new>
...
new (this) SMatrix(cx);
Strictly speaking, I think that's not valid C++ either, since you are
effectively creating two objects in the same spot, but it ought to work.
Jason
More information about the Gcc
mailing list