visual c++中的Mixin类问题
Mixin class issue in visual c++
我正试图编译这个代码,最初是为vs2005在vs2008上编写的。我得到了错误。下面是代码。另外,我有这些提供mixin行为的头文件,它们是无错误的。
错误:
syntax error missing ';' before '<' LINE 86
missing type specifier - int assumed. Note: C++ does not support default int. LINE 86
'SimpleVehicleMB_1' undeclared identifier LINE 90
'AnnotationMixin' unspecialized class template cannot be used as a tempalte argument for tempalte parameter 'Super', expected a real type. LINE 94
'AnnotationMixin' use of class template requires template argument list LINE 94
'SteerLibraryMixin' use of claas template requires template argument list LINE 101
#ifndef OPENSTEER_SIMPLEVEHICLE_MB_H
#define OPENSTEER_SIMPLEVEHICLE_MB_H
#include "AbstractVehicle.h"
#include "SteerLibrary.h"
#include "Annotation.h"
namespace OpenSteer {
// ----------------------------------------------------------------------------
// SimpleVehicle_1 adds concrete LocalSpace methods to AbstractVehicle LINE 86
typedef LocalSpaceMixinMB<AbstractVehicle> SimpleVehicleMB_1;
// SimpleVehicle_2 adds concrete annotation methods to SimpleVehicle_1 LINE 90
typedef AnnotationMixin<SimpleVehicleMB_1> SimpleVehicleMB_2;
// SimpleVehicle_3 adds concrete steering methods to SimpleVehicle_2 LINE 94
typedef SteerLibraryMixin<SimpleVehicleMB_2> SimpleVehicleMB_3;
// SimpleVehicle adds concrete vehicle methods to SimpleVehicle_3
class SimpleVehicleMB : public SimpleVehicleMB_3
{
public:
// constructor LINE 101 is the '{' above
SimpleVehicleMB ();
// destructor
~SimpleVehicleMB ();
// reset memory backend
static void resetBackend()
{
MemoryBackend::reset();
}
// reset vehicle state
void reset (void)
{
// reset LocalSpace state
resetLocalSpace ();
// reset SteerLibraryMixin state
// (XXX this seems really fragile, needs to be redesigned XXX)
SimpleVehicleMB_3::reset ();
setMass (1); // mass (defaults to 1 so acceleration=force)
setSpeed (0); // speed along Forward direction.
setRadius (0.5f); // size of bounding sphere
setMaxForce (0.1f); // steering force is clipped to this magnitude
setMaxSpeed (1.0f); // velocity is clipped to this magnitude
// reset bookkeeping to do running averages of these quanities
resetSmoothedAcceleration ();
}
// get/set mass
float mass (void) const {return mb->mass(mb_id);}
float setMass (float m) {return mb->setMass(mb_id, m);}
// get velocity of vehicle
Vec3 velocity (void) const {return forward() * speed();}
// get/set speed of vehicle (may be faster than taking mag of velocity)
float speed (void) const {return mb->speed(mb_id);}
float setSpeed (float s) {return mb->setSpeed(mb_id, s);}
// size of bounding sphere, for obstacle avoidance, etc.
float radius (void) const {return mb->radius(mb_id);}
float setRadius (float m) {return mb->setRadius(mb_id, m);}
// get/set maxForce
float maxForce (void) const {return mb->maxForce(mb_id);}
float setMaxForce (float mf) {return mb->setMaxForce(mb_id, mf);}
// get/set maxSpeed
float maxSpeed (void) const {return mb->maxSpeed(mb_id);}
float setMaxSpeed (float ms) {return mb->setMaxSpeed(mb_id, ms);}
// apply a given steering force to our momentum,
// adjusting our orientation to maintain velocity-alignment.
void applySteeringForce (const Vec3& force, const float deltaTime);
// the default version: keep FORWARD parallel to velocity, change
// UP as little as possible.
virtual void regenerateLocalSpace (const Vec3& newVelocity,
const float elapsedTime);
// alternate version: keep FORWARD parallel to velocity, adjust UP
// according to a no-basis-in-reality "banking" behavior, something
// like what birds and airplanes do. (XXX experimental cwr 6-5-03)
void regenerateLocalSpaceForBanking (const Vec3& newVelocity,
const float elapsedTime);
// adjust the steering force passed to applySteeringForce.
// allows a specific vehicle class to redefine this adjustment.
// default is to disallow backward-facing steering at low speed.
// xxx experimental 8-20-02
virtual Vec3 adjustRawSteeringForce (const Vec3& force,
const float deltaTime);
// apply a given braking force (for a given dt) to our momentum.
// xxx experimental 9-6-02
void applyBrakingForce (const float rate, const float deltaTime);
// predict position of this vehicle at some time in the future
// (assumes velocity remains constant)
Vec3 predictFuturePosition (const float predictionTime) const;
Vec3 smoothedAcceleration (void) {return mb->smoothedAcceleration(mb_id);}
Vec3 resetSmoothedAcceleration (const Vec3& value = Vec3::zero)
{
mb->setSmoothedAcceleration(mb_id, value);
return value;
}
// give each vehicle a unique number
int serialNumber;
static int serialNumberCounter;
// draw lines from vehicle's position showing its velocity and acceleration
void annotationVelocityAcceleration (float maxLengthA, float maxLengthV);
void annotationVelocityAcceleration (float maxLength)
{annotationVelocityAcceleration (maxLength, maxLength);}
void annotationVelocityAcceleration (void)
{annotationVelocityAcceleration (3, 3);}
// set a random "2D" heading: set local Up to global Y, then effectively
// rotate about it by a random angle (pick random forward, derive side).
void randomizeHeadingOnXZPlane (void)
{
setUp (Vec3::up);
setForward (RandomUnitVectorOnXZPlane ());
setSide (localRotateForwardToSide (forward()));
}
};
} // namespace OpenSteer
// ----------------------------------------------------------------------------
#endif // OPENSTEER_SIMPLEVEHICLE_MB_H
你的错误信息(当我写这篇文章时发布)说
语法错误,在'<'之前缺少';'
在代码中,第一个'<'在这一行:
typedef LocalSpaceMixinMB<AbstractVehicle> SimpleVehicleMB_1;
这一行是问题表现出来的地方被随后抱怨SimpleVehicleMB_1
的消息所证实。
显然,此时还没有定义模板和/或类型。
根据我写这篇文章时提供的信息,最有可能的是没有定义的模板LocalSpaceMixinMB
。例如,您忘记了包含相关的标题。也可能是标题"AbstractVehicle.h"
有问题。
但是你没有显示相关的代码,所以(目前)唯一要添加的是,请记住,错误的原因要么是在错误表现出来的地方,要么是在翻译单元的预处理源代码的早期某个地方,例如在早期包含的头文件中。
干杯,hth。
相关文章:
- 警告处理为错误这里有什么问题
- 最小硬币更换问题(自上而下方法)
- 为"adjacent"变量赋值时出现问题
- 我的神经网络不起作用 [XOR 问题]
- 在Ubuntu 16.04上安装Cilk时出现问题
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 编译包含字符串的代码时遇到问题
- Project Euler问题4的错误解决方案
- 问题:什么是QAbstractItemView::NoEditTriggers的反面
- 在编译C++代码(具有dlib和opencv)到WASM时面临问题
- 在进程中对同一管道进行读取和写入时C++管道出现问题
- 静态数据成员的问题-修复链接错误会导致编译器错误
- C++ 雷神库 - 使用资源加载器类时出现问题(不命名类型)
- 一个关于在C++中重载布尔运算符的问题
- 首要问题的答案让值班员搞错了
- setlocale的C++土耳其字符串问题
- 如何重构类层次结构以避免菱形问题
- 基于boost的程序的静态链接——zlib问题
- visual c++中的Mixin类问题
- 这是解决mixin构造函数问题的有效方法吗