Visual C 中的 Mixin 类问题

发布于 2024-12-11 05:32:06 字数 6862 浏览 0 评论 0原文

我正在尝试在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

野の 2024-12-18 05:32:06

您的错误消息(如我撰写本文时发布的)所示

语法错误缺少“;”在“<”之前

在代码中,您呈现第一个“<”位于这一行:

typedef LocalSpaceMixinMB<AbstractVehicle> SimpleVehicleMB_1;

这一行是问题本身表现出来的地方,随后抱怨 SimpleVehicleMB_1 的消息证实了这一点。

显然此时模板和/或类型尚未定义。

根据我撰写本文时提供的信息,很可能是模板 LocalSpaceMixinMB 未定义。就像,您忘记包含相关标题。或者,也可能是标头 "AbstractVehicle.h" 有问题。

但是您没有显示相关代码,因此(目前)唯一需要添加的是,请记住错误的原因要么是在错误出现的地方,要么是在翻译的预处理源代码中较早的地方单元,例如在早期包含的标头中。

干杯&呵呵,

Your error message (as posted when I'm writing this) says

syntax error missing ';' before '<'

In the code you're presenting the first '<' is in this line:

typedef LocalSpaceMixinMB<AbstractVehicle> SimpleVehicleMB_1;

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.,

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文