Are there any commonly used C++ compilers that would allow this syntax?
pI am new to C++ and trying to get a
href=https://svn.code.sf.net/p/extremetuxracer/code/trunk/
rel=nofollowthis/a open source program (developed for/in linux) to compile
and run in xcode on OS X. /p pWhen I compiler and run the code I get a LOT
of errors (more than xcode is willing to count) like this codeuse of
undeclared identifier 'x'/code or this codeuse of undeclared identifier
'y'/code/p pHere is a sample of the code throwing the error: /p
precodetemplatelt;typename Tgt; struct TVector2 { T x, y; TVector2(T _x =
0.0, T _y = 0.0) : x(_x), y(_y) {} double Length() const { return
sqrt(static_castlt;doublegt;(x*x + y*y)); } double Norm();
TVector2lt;Tgt;amp; operator*=(T f) { x *= f; y *= f; return *this; }
TVector2lt;Tgt;amp; operator+=(const TVector2lt;Tgt;amp; v) { x += v.x; y
+= v.y; return *this; } TVector2lt;Tgt;amp; operator-=(const
TVector2lt;Tgt;amp; v) { x -= v.x; y -= v.y; return *this; } }; struct
TVector3 : public TVector2lt;Tgt; { T z; TVector3(T _x = 0.0, T _y = 0.0,
T _z = 0.0) : TVector2lt;Tgt;(_x, _y), z(_z) {} double Length() const {
return sqrt(static_castlt;doublegt;(x*x + y*y + z*z)); //use of undeclared
identifier x } double Norm(); TVector3lt;Tgt;amp; operator*=(T f) { x *=
f; y *= f; z *= f; return *this; } /code/pre pTo my eye as an
inexperienced C++ programmer, it looks like x and y are simply undeclared
local variables. I can get the compiler to get rid of the errors by simply
declaring the variables, like this... /p precodestruct TVector3 : public
TVector2lt;Tgt; { T z; T x; T y; /code/pre pHowever, the sheer number of
these errors makes me think that /p ol liThere might be (reasonably
common) versions of C++ compilers that allow you to declare a variable x
as _x. That would explain why the source I downloaded has so many compiler
errors./li liMaybe I got a bad batch of the source and I should not waste
my time getting it to compile because the source is screwy somehow./li /ol
pCan an experienced C++ developer explain what might be going on?/p
No comments:
Post a Comment