MotionDirection
静的メンバーを持つクラスがあります。クラスのソースコードは以下です。しかし、クラスの静的メンバーを初期化できず、その理由を知ることができます。したがって、問題は にありMotionDirection.cpp
ます。コンパイラ エラーの詳細については、コメントを参照してください。
MotionDirection.h
#ifndef MOTION_DIRECTION
#define MOTION_DIRECTION
namespace game{
class IntPosition;
class MotionDirection {
private:
IntPosition* positionDisplacement;
float angle;
MotionDirection* returnDirection;
public:
MotionDirection( IntPosition* positionDisplacement, float angle );
void setReturnDirection ( MotionDirection* returnDirection );
IntPosition* getPositionDisplacement();
float getAngle();
MotionDirection* getReturnDirection();
static MotionDirection* NONE;
static MotionDirection* LEFT;
static MotionDirection* RIGHT;
static MotionDirection* UP;
static MotionDirection* DOWN;
static void initStatics();
};
}
#endif
MotionDirection.cpp
#include "MotionDirection.h"
#include "IntPosition.h"
namespace game{
MotionDirection::NONE = new MotionDirection ( new IntPosition( 0, 0), 0.0f );
// here I get an error:
// MotionDirection.cpp:10:5: error: 'NONE' in 'class game::MotionDirection' does not name a type
MotionDirection::MotionDirection( IntPosition* positionDisplacement, float angle ) {
this->positionDisplacement = positionDisplacement;
this->angle = angle;
}
void MotionDirection::setReturnDirection ( MotionDirection* returnDirection ) {
this->returnDirection = returnDirection;
}
IntPosition* MotionDirection::getPositionDisplacement() {
return positionDisplacement;
}
float MotionDirection::getAngle() {
return angle;
}
MotionDirection* MotionDirection::getReturnDirection() {
return returnDirection;
}
void MotionDirection::initStatics () {
MotionDirection::NONE = new MotionDirection ( new IntPosition( 0, 0), 0.0f );
MotionDirection::LEFT = new MotionDirection ( new IntPosition(-1, 0), 180.0f );
MotionDirection::RIGHT = new MotionDirection ( new IntPosition( 1, 0), 0.0f );
MotionDirection::UP = new MotionDirection ( new IntPosition( 0,-1), 90.0f );
MotionDirection::DOWN = new MotionDirection ( new IntPosition( 0, 1), 270.0f );
}
MotionDirection::initStatics();
// or here I get an error:
// MotionDirection.cpp:45:35: error: expected constructor, destructor, or type conversion before ';' token
}
PS これは Android-NDK プロジェクトです。コンパイルは cygwin コンソールから実行します。