www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.gnu
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript

c++ - macro

↑ ↓ ← Roland <rv ronetech.com> writes:
i have the macro:

#define __OPEQVAL(val,op)   ( int i; for (i=0; i<DIM; i++) coord[i] op
val; return *this )

and the class:

template <class T, int DIM>
class npoint {
public:
.
.
    npoint<T,DIM>& operator+=(const T a) {
        __OPEQVAL(a,+=);                                    //<-----
here
    }
.
.
public:
    T coord[DIM];
};

does not compile: "identifier found in abstract declarator."
if i write like below, it compiles:

    npoint<T,DIM>& operator+=(const T a) {
        int i; for (i=0; i<DIM; i++) coord[i] += a; return
*this;           //same but macro expanded
    }

my questions:
    - is it suposed to compile ?, if not, in few word why ? (just for my
general culture)
    - do i missed something, is there a way to make it compile ?

(I hate cut and past code, write more than once similar code. i can't
calculate how much time i lost trying to go faster)

thanks

roland
Apr 05 2002
→ "Walter" <walter digitalmars.com> writes:
Looks like the trouble is that (int looks like the start of a cast.

"Roland" <rv ronetech.com> wrote in message
news:3CAD70CD.643A290C ronetech.com...
 i have the macro:

 #define __OPEQVAL(val,op)   ( int i; for (i=0; i<DIM; i++) coord[i] op
 val; return *this )

 and the class:

 template <class T, int DIM>
 class npoint {
 public:
 .
 .
     npoint<T,DIM>& operator+=(const T a) {
         __OPEQVAL(a,+=);                                    //<-----
 here
     }
 .
 .
 public:
     T coord[DIM];
 };

 does not compile: "identifier found in abstract declarator."
 if i write like below, it compiles:

     npoint<T,DIM>& operator+=(const T a) {
         int i; for (i=0; i<DIM; i++) coord[i] += a; return
 *this;           //same but macro expanded
     }

 my questions:
     - is it suposed to compile ?, if not, in few word why ? (just for my
 general culture)
     - do i missed something, is there a way to make it compile ?

 (I hate cut and past code, write more than once similar code. i can't
 calculate how much time i lost trying to go faster)

 thanks

 roland

Apr 05 2002
Jan Knepper <jan smartsoft.cc> writes:
Roland, have you tried it as:

#define __OPEQVAL(val,op)   { int i; for (i=0; i<DIM; i++) coord[i] op val;
return *this; }

i.e {} instead of ()?


Jan



Roland wrote:

 i have the macro:

 #define __OPEQVAL(val,op)   ( int i; for (i=0; i<DIM; i++) coord[i] op
 val; return *this )

 and the class:

 template <class T, int DIM>
 class npoint {
 public:
 .
 .
     npoint<T,DIM>& operator+=(const T a) {
         __OPEQVAL(a,+=);                                    //<-----
 here
     }
 .
 .
 public:
     T coord[DIM];
 };

 does not compile: "identifier found in abstract declarator."
 if i write like below, it compiles:

     npoint<T,DIM>& operator+=(const T a) {
         int i; for (i=0; i<DIM; i++) coord[i] += a; return
 *this;           //same but macro expanded
     }

 my questions:
     - is it suposed to compile ?, if not, in few word why ? (just for my
 general culture)
     - do i missed something, is there a way to make it compile ?

 (I hate cut and past code, write more than once similar code. i can't
 calculate how much time i lost trying to go faster)

 thanks

 roland

Apr 05 2002
↑ ↓ → Roland <rv ronetech.com> writes:
Jan Knepper a écrit :

 Roland, have you tried it as:

 #define __OPEQVAL(val,op)   { int i; for (i=0; i<DIM; i++) coord[i] op val;
 return *this; }

 i.e {} instead of ()?

 Jan

okay, it seem to work (it compiles) ! thanks jan roland
Apr 06 2002