Jiaoma / chipmunk-physics

Automatically exported from code.google.com/p/chipmunk-physics
MIT License
0 stars 0 forks source link

c++ conflict operators #32

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
Only including chipmunk.h inside a c++ file and try compile.

What is the expected output? What do you see instead?
(...)
/usr/include/chipmunk/chipmunk.h: In function ‘cpVect operator-(cpVect)’:
/usr/include/chipmunk/chipmunk.h:159: error: declaration of C function 
‘cpVect operator-(cpVect)’ conflicts with
/usr/include/chipmunk/chipmunk.h:157: error: previous declaration ‘cpVect 
operator-(cpVect, cpVect)’ here

What version of the product are you using?
Chipmunk 5.3.4

Examining the header file I found this:

#ifdef __cplusplus
}

static inline cpVect operator *(const cpVect v, const cpFloat s){return 
cpvmult(v, s);}
static inline cpVect operator +(const cpVect v1, const cpVect v2){return 
cpvadd(v1, v2);}
static inline cpVect operator -(const cpVect v1, const cpVect v2){return 
cpvsub(v1, v2);}
static inline cpBool operator ==(const cpVect v1, const cpVect v2){return 
cpveql(v1, v2);}
static inline cpVect operator -(const cpVect v){return cpvneg(v);}

#endif

Original issue reported on code.google.com by teritri...@gmail.com on 18 Dec 2010 at 3:46

GoogleCodeExporter commented 8 years ago
Also there are a bracket inside the "ifdef".

Original comment by teritri...@gmail.com on 18 Dec 2010 at 3:53

GoogleCodeExporter commented 8 years ago
What compiler/version are you using?

Apparently it doesn't like that I've defined both a unary and binary minus 
operator, but it works just fine with g++ 4.2.1.

What's wrong with the bracket? It's closing the extern C chunk.

Original comment by slemb...@gmail.com on 18 Dec 2010 at 4:16

GoogleCodeExporter commented 8 years ago
Oh, wait a minute.

"declaration of C function ‘cpVect operator-(cpVect)’ ..."

So why does it think that it's still in the extern C block? Hrm. I have no idea 
what is going on then.

Original comment by slemb...@gmail.com on 18 Dec 2010 at 4:23

GoogleCodeExporter commented 8 years ago
g++ version 4.4.5

Problem with the bracket

#ifdef __cplusplus
}//end braket of extern "C"
//...
#endif

Correction

#ifdef __cplusplus
}//end bracket of extern "C"
#endif

#ifdef __cplusplus
//...
#endif

I think that this will avoid headaches later.

The operators with vectors works fine now with a test that i did:

original

static inline cpVect operator -(const cpVect v1, const cpVect v2){return 
cpvsub(v1, v2);}
static inline cpBool operator ==(const cpVect v1, const cpVect v2){return 
cpveql(v1, v2);}
static inline cpVect operator -(const cpVect v){return cpvneg(v);}

Changue the minus operator of
static inline cpVect operator -(const cpVect v){return cpvneg(v);}

by, for example

static inline cpVect operator !(const cpVect v){return cpvneg(v);}

Compiles fine and...

cpvect test = {1, 1}
test = !test;
//{-1, -1} works very well

but i dont know if is ok for you

Original comment by teritri...@gmail.com on 18 Dec 2010 at 5:51