?
=?ISO-8859-1?Q?Christian_Brechb=FChler?=
I get a compile time error that I don't understand.
======================================= begin constructor.cc ======
struct Negate {};
class A {
int i;
public:
A(double x ): i(int(x)) {}; // 0
A(Negate ): i(-1 ) {}; // 1
A(double, int ii): i(4*ii ) {}; // 2
A(Negate, int ii): i( -ii ) {}; // 3
};
void foob(Negate n, int x) {
A a(n,x);
};
template <typename T>
void f() {
A a0(3.0);
A a1(Negate());
A a2(1.4 , 3);
A a3(Negate(), 6); // error
Negate dummy;
A a4(dummy , 6);
A a5 = A(Negate(), 6);
foob(Negate(), 6);
}
======================================= end constructor.cc ======
This gives me two errors on the indicated line. I intend to initialize a3
directly with the third constructor, just like a4 and a (and a5?).
======================================= begin compiler output ======
make -k constructor.o
g++ -c -o constructor.o constructor.cc
constructor.cc: In function `void f()':
constructor.cc:22: type specifier omitted for parameter
constructor.cc:22: parse error before numeric constant
make: *** [constructor.o] Error 1
======================================= end compiler output ======
I'd prefer not to use a dummy object. What is the correct syntax? And what does
the error try to tell me?
Thanks
Christian
======================================= begin constructor.cc ======
struct Negate {};
class A {
int i;
public:
A(double x ): i(int(x)) {}; // 0
A(Negate ): i(-1 ) {}; // 1
A(double, int ii): i(4*ii ) {}; // 2
A(Negate, int ii): i( -ii ) {}; // 3
};
void foob(Negate n, int x) {
A a(n,x);
};
template <typename T>
void f() {
A a0(3.0);
A a1(Negate());
A a2(1.4 , 3);
A a3(Negate(), 6); // error
Negate dummy;
A a4(dummy , 6);
A a5 = A(Negate(), 6);
foob(Negate(), 6);
}
======================================= end constructor.cc ======
This gives me two errors on the indicated line. I intend to initialize a3
directly with the third constructor, just like a4 and a (and a5?).
======================================= begin compiler output ======
make -k constructor.o
g++ -c -o constructor.o constructor.cc
constructor.cc: In function `void f()':
constructor.cc:22: type specifier omitted for parameter
constructor.cc:22: parse error before numeric constant
make: *** [constructor.o] Error 1
======================================= end compiler output ======
I'd prefer not to use a dummy object. What is the correct syntax? And what does
the error try to tell me?
Thanks
Christian