2011-10-22 92 views
0

我想編譯這個代碼,它最初是針對vs2008上的vs2005編寫的。我收到錯誤。以下是代碼。此外,我有這些頭文件提供混合行爲,他們是沒有錯誤的。Mixin類在Visual C++中的問題

錯誤:

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 
+0

告訴我們哪一行得到哪個錯誤。 – selalerer

+0

在評論中添加了行號。 thanku –

回答

1

你的錯誤信息(當我在寫這貼)說

語法錯誤缺少 ';'前「<」

在代碼中你所講的第一個「<」是在這一行:

typedef LocalSpaceMixinMB<AbstractVehicle> SimpleVehicleMB_1; 

此行是哪裏出了問題表現被隨後證實消息抱怨SimpleVehicleMB_1

顯然,模板和/或類型在此處未定義。

隨着我寫這篇文章時提供的信息,最有可能的是它沒有定義的模板LocalSpaceMixinMB。就像,你忘記了包含相關的標題。也可能是它的標題"AbstractVehicle.h"有問題。

但是您沒有顯示相關代碼,因此唯一要添加的內容是(現在),請記住,錯誤的原因要麼是錯誤自身出現的位置,要麼是之前的預處理源翻譯單元的代碼,例如在較早的包含標題中。

乾杯& hth。,

+0

嗨,感謝您的回覆。我發佈了另一個更專注的問題。你能看看嗎? http://stackoverflow.com/q/7858555/954974 –