Help: constructor syntax
From: Christian Brechbühler (c_brechbuehler_at_yhaoo.com)
Date: 10/31/03
- Next message: Rolf Magnus: "Re: Pointers and Arrays in C"
- Previous message: Dave Vandervies: "Re: Pointers and Arrays in C"
- Next in thread: Josephine Schafer: "Re: constructor syntax"
- Reply: Josephine Schafer: "Re: constructor syntax"
- Reply: Karl Heinz Buchegger: "Re: Help: constructor syntax"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 31 Oct 2003 00:00:16 GMT
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
- Next message: Rolf Magnus: "Re: Pointers and Arrays in C"
- Previous message: Dave Vandervies: "Re: Pointers and Arrays in C"
- Next in thread: Josephine Schafer: "Re: constructor syntax"
- Reply: Josephine Schafer: "Re: constructor syntax"
- Reply: Karl Heinz Buchegger: "Re: Help: constructor syntax"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|