Help: constructor syntax

From: Christian Brechbühler (c_brechbuehler_at_yhaoo.com)
Date: 10/31/03


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



Relevant Pages

  • Re: constructor syntax
    ... > struct Negate; ... > void foob(Negate n, int x) { ... there should be no semicolon after function definitions. ...
    (comp.lang.cpp)
  • Help in Java swings(internal Frame)
    ... public int getSize() ... public void valueChanged{ ... private JScrollPane scrollPane1; ... public class PeakContainer extends JInternalFrame ...
    (comp.lang.java.programmer)
  • [PATCH] get rid if __cpuinit and __cpuexit
    ... unsigned long action, void *hcpu) ... unsigned int cpu = hcpu; ... -static int __cpuinit ... __cpu_up(unsigned int cpu) ...
    (Linux-Kernel)
  • [PATCH,RFC 2.6.14 09/15] KGDB: SuperH-specific changes
    ... This adds basic support for KGDB on SuperH as well as adding some architecture ... -static int kgdb_uart_getchar ... -static void kgdb_uart_putchar ... * The command-line option can include a serial port specification ...
    (Linux-Kernel)
  • problem in java swings
    ... public int getSize() ... public void valueChanged{ ... private JScrollPane scrollPane1; ... public class PeakContainer extends JInternalFrame ...
    (comp.lang.java.programmer)