This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Code compiled with 2.7, doesn't with egcs, please help


>>>>> 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]