Visual C 中的 Mixin 类问题
我正在尝试在 vs2008 上编译最初为 vs2005 编写的这段代码。我收到错误。以下是代码。另外,我有这些提供 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
I am trying to compile this code that was originally written for vs2005 on vs2008. i am getting the errors. Following is the code. Additionally i have these header files providing mixin behavior and they are error free.
Errors:
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的错误消息(如我撰写本文时发布的)所示
在代码中,您呈现第一个“<”位于这一行:
这一行是问题本身表现出来的地方,随后抱怨
SimpleVehicleMB_1
的消息证实了这一点。显然此时模板和/或类型尚未定义。
根据我撰写本文时提供的信息,很可能是模板
LocalSpaceMixinMB
未定义。就像,您忘记包含相关标题。或者,也可能是标头"AbstractVehicle.h"
有问题。但是您没有显示相关代码,因此(目前)唯一需要添加的是,请记住错误的原因要么是在错误出现的地方,要么是在翻译的预处理源代码中较早的地方单元,例如在早期包含的标头中。
干杯&呵呵,
Your error message (as posted when I'm writing this) says
In the code you're presenting the first '<' is in this line:
That this line is where the problem manifests itself is borne out by subsequent messages complaining about
SimpleVehicleMB_1
.So evidently the template and/or the type is not defined at this point.
With the information provided as I'm writing this, most likely it's the template
LocalSpaceMixinMB
that's not defined. Like, you have forgotten to include the relevant header. It could alternatively be that it's the header"AbstractVehicle.h"
that has a problem.But you're not showing the relevant code so the only thing to add (for now) is, keep in mind that an error's cause is either at the point where the error manifests itself, or somewhere earlier in the preprocessed source code of the translation unit, e.g. in an earlier included header.
Cheers & hth.,