错误 C2146:语法错误:标识符'ContextRecord'之前缺少';'



我有一个头文件,其中包含所有类的函数,包括代码,所以类没有CPP文件。一切工作。我添加了cpp文件,并将函数代码移动到那里,现在我在编译时得到这个错误。我在((x86)microsoft sdk windowsv7.0aincludewinnt.h(6361))中得到错误的标头甚至不包括在我更改的文件中。有人知道这可能是什么原因吗?我可以提供代码,我只是不知道什么会有帮助。

CPP文件

#include "Fisherman.h"
void Fisherman::Initialise(){
memset((void*)&mListener, 0, sizeof(X3DAUDIO_LISTENER));
memset((void*)&mEmitter, 0, sizeof(X3DAUDIO_EMITTER));
memset((void*)&mDSPSettings, 0, sizeof(X3DAUDIO_DSP_SETTINGS));
XAUDIO2_VOICE_DETAILS details;
mCastSplash->GetSourceVoice()->GetVoiceDetails(&details);       
mEmitter.ChannelCount = details.InputChannels; 
mEmitter.CurveDistanceScaler = 1.0f;
X3DAUDIO_VECTOR emitterPos = { 0.0f, 0.0f, 0.0f}; 
mEmitter.Position = emitterPos;
X3DAUDIO_VECTOR emitterVel = { 0.0f, 0.0f, 0.0f }; 
mEmitter.Velocity = emitterVel;
mDSPSettings.SrcChannelCount = mEmitter.ChannelCount; 
mDSPSettings.DstChannelCount = mXACore->GetChannelCount();
FLOAT32 * matrix = new FLOAT32[mDSPSettings.SrcChannelCount * mDSPSettings.DstChannelCount];
mDSPSettings.pMatrixCoefficients = matrix;
X3DAUDIO_VECTOR front = { 0.0f, 0.0f, 1.0f }; 
X3DAUDIO_VECTOR top = { 0.0f, 1.0f, 0.0f }; 
mListener.OrientFront = front;
mListener.OrientTop = top;
X3DAUDIO_VECTOR listenerVel = {0.0f, 0.0f, 0.0f};
mListener.Velocity = listenerVel;
X3DAUDIO_VECTOR listenerPos = { 0.0f, 0.0f, 0.0f }; 
mListener.Position = listenerPos;
}
void Fisherman::Rotate (int MouseDeltaX){
X3DAUDIO_VECTOR input = mListener.OrientFront;
X3DAUDIO_VECTOR result;
float theta = -(X3DAUDIO_PI/1000)*MouseDeltaX;
float cs = cos(theta);
float sn = sin(theta);
if(cs < 0.00001) cs = 0.0f;
result.x = input.x * cs - input.z * sn;
result.z = input.x * sn + input.z * cs;
result.y = 0.0f;
mListener.OrientFront = result;
}
bool Fisherman::Cast(Fish* aFish){
mCast->Play(0);
mCastOut = true;
mFish = aFish;
X3DAUDIO_VECTOR seg_v = Multiply(mListener.OrientFront, 30);
X3DAUDIO_VECTOR pt_v = {mFish->GetX(), 0.0f, mFish->GetZ()};
float proj_v_length = Dot(pt_v, mListener.OrientFront);
X3DAUDIO_VECTOR proj_v = Multiply(mListener.OrientFront, proj_v_length);
X3DAUDIO_VECTOR dist_v = Subtract(pt_v, proj_v);
if(VectorLength(dist_v) < mFish->GetRadius()){
    mEmitter.Position = mFish->GetEmitter().Position;
    return true;
}else{
    mEmitter.Position = Multiply(mListener.OrientFront, 15);
    return false;
}
}
void Fisherman::ReelIn(Fish* aFish){
mFish = aFish;
mFish->MoveCloser(mReelSpeed);
mReelingIn = true;
}
void Fisherman::ReelOut(Fish* aFish){
mFish = aFish;
mFish->MoveFurther();
mReelingIn = false;
}
void Fisherman::SetReelSpeed(float deltaTime){ 
float reelSpeed = 1.0f - deltaTime;
if(reelSpeed < 0.0f){
    reelSpeed = 0.0f;
}
if(reelSpeed > 10){
    mReelSpeedList.push_back(reelSpeed);
    if(mReelSpeedList.size() > 3){
        mReelSpeedList.pop_front();
    }
    reelSpeed = 0.0f;
    std::list<float>::const_iterator iterator;
    for (iterator = mReelSpeedList.begin(); iterator != mReelSpeedList.end(); ++iterator){
            reelSpeed += *iterator;
    }

    mReelSpeed = reelSpeed/mReelSpeedList.size();
}else
    mReelSpeed = reelSpeed;
mReelClickTimer = 0.1 / mReelSpeed;
}
void Fisherman::PlayReelClick(){
if(!mReelClick[0]->IsPlaying()){
    mReelClick[0]->Play(0);
}else if(!mReelClick[1]->IsPlaying()){
    mReelClick[1]->Play(0);
}else if(!mReelClick[2]->IsPlaying()){
    mReelClick[2]->Play(0);
}else if(!mReelClick[3]->IsPlaying()){
    mReelClick[3]->Play(0);
}else if(!mReelClick[4]->IsPlaying()){
    mReelClick[4]->Play(0);
}else {
    return;
}
}
bool Fisherman::NothingPlaying(){ // check to see if any sounds are playing
if(mCast->IsPlaying())return false;
if(mCastSplash->IsPlaying())return false;
for(int i =0; i < REEL_CLICK_OBJECTS; i++){
    if(mReelClick[i]->IsPlaying()){
        return false;
    }
}
return true;
} 
void Fisherman::SetReelingIn(bool isReelingIn){
mReelingIn = isReelingIn;
}
void Fisherman::SetCastOut(bool hasCastOut){
    mCastOut = hasCastOut;
}
float Fisherman::GetReelClickTime(){
    return mReelClickTimer/CLICK_TIMER_MULTIPLIER;
}
bool Fisherman::IsReelingIn(){
    return mReelingIn;
}
float Fisherman::GetReelSpeed(){
    return mReelSpeed;
}
X3DAUDIO_LISTENER Fisherman::GetListener(){
    return mListener;
}
X3DAUDIO_EMITTER Fisherman::GetEmitter(){
    return mEmitter;
}
X3DAUDIO_DSP_SETTINGS Fisherman::GetSettings(){
    return mDSPSettings;
}
XASound* Fisherman::GetCastSound(){
    return mCast;
}
XASound* Fisherman::GetCastSplashSound(){
    return mCastSplash;
}
bool Fisherman::HasCastSplashed(){
    return mCastSplashBool;
}
void Fisherman::SetCastSplashed(bool splashed){
    mCastSplashBool = splashed;
}
bool Fisherman::IsCastOut(){
    return mCastOut;
}

标题:

#ifndef _FISHERMAN_H_
#define _FISHERMAN_H_
#include <X3DAudio.h>
#include <math.h>
#include <list>
#include "VectorCalculations.h"
#include "Fish.h"
#include "XASound.hpp"
using AllanMilne::Audio::XASound;
const float CLICK_TIMER_MULTIPLIER = 2.5f;
const int REEL_CLICK_OBJECTS = 5;
class Fisherman{
public:
    Fisherman(XACore* aXACore, XASound *cast, XASound *castSplash, std::list<XASound*> reelClickList)
        : // a Fish Object pointer for the fisherman to interact with.
        mFish (NULL), mXACore (aXACore),
        //XASound objects with sounds for the fisherman
        mCast (cast), mCastSplash (castSplash)
    {
        mReelSpeedList.clear();
        for(int i = 0; i < REEL_CLICK_OBJECTS; i++){
            mReelClick[i] = reelClickList.front();
            mReelClick[i]->SetVolume(2.0f);
            reelClickList.pop_front();
            mReelClickList.push_back(mReelClick[i]);
        }
        mCastSplash->SetVolume(7.0f);
        mXACore = aXACore;
        mCastSplashBool = false;
        mCastOut = false;
        mReelingIn = false;
        mCastDistance = 0.0f;
        Initialise();
    }
    ~Fisherman(){}
    void Initialise();
    void Rotate(int MouseDeltaX);
    bool Cast(Fish* aFish);
    void ReelIn(Fish* aFish);
    void ReelOut(Fish* aFish);
    void SetReelSpeed(float deltaTime);
    void PlayReelClick();
    bool NothingPlaying(); // check to see if any sounds are playing
    void SetFront(X3DAUDIO_VECTOR front);
    void SetReelingIn(bool isReelingIn);
    void SetCastOut(bool hasCastOut);
    float GetReelClickTime();
    bool IsReelingIn();
    float GetReelSpeed();
    X3DAUDIO_LISTENER GetListener();
    X3DAUDIO_EMITTER GetEmitter();
    X3DAUDIO_DSP_SETTINGS GetSettings();
    XASound* GetCastSound();
    XASound* GetCastSplashSound();
    bool HasCastSplashed();
    void SetCastSplashed(bool splashed);
    bool IsCastOut();

private:
    XACore *mXACore;
    XASound *mCast;
    XASound *mCastSplash;
    XASound *mReelClick[REEL_CLICK_OBJECTS];

    float mCastDistance; 
    float mReelClickTimer;
    float mReelSpeed;
    std::list<float> mReelSpeedList;
    std::list<XASound*> mReelClickList; 
    X3DAUDIO_LISTENER mListener; 
    X3DAUDIO_EMITTER mEmitter;
    X3DAUDIO_DSP_SETTINGS mDSPSettings;
    Fish *mFish;
    bool mCastOut;
    bool mCastSplashBool;
    bool mReelingIn;
};

#endif

在头文件的顶部包含windows.h解决了这个问题。

错误是否也显示PCONTEXT undefined ?

尝试在#include <X3DAudio.h>之前添加#include <Windows.h>

关于unresolved external symbol评论的回复:

这是因为您没有在cpp文件中定义Fisherman::SetFront

完整的代码将是有帮助的。你还记得给函数的名字命名空间吗?

class A { void foo() { } };
=>
class A { void foo(); }
void A::foo() { ... }

等等?

最快的方法是在它工作时恢复到状态,而不是一次移动整个函数,而是一次只移动一个函数。当问题出现时,你可以给我们具体的代码,或者试着自己修复它。

很可能在这行之前的某个地方漏了一个';'。

仔细检查你的代码,记住你在cpp文件中定义的所有东西都必须已经在你的类定义中声明过。

我想发表评论,但显然我不被允许。

无论如何,作为一种更简单的方式,让我们感受到你在做什么,一定要发布你的代码——它不必完全是你使用的,但应该是一段简洁的通用代码,突出你是如何做某事的。(SSCCE)如果它真的是一个错误在你如何键入它,它会很好有你的确切代码,但把它放在pastebin上,并提供一个链接,这样这个页面不会结束与大量的代码。

编辑:

winnt.h显然会导致各种各样的问题:处理winnt.h时出现奇怪的编译错误据我所知,它是用来为winAPI特定的头提供定义的。在该线程中提出的解决方案之一是在包含需要这些定义的头文件之前从不同的窗口头文件中获取定义。

相关内容

  • 没有找到相关文章

最新更新