简体   繁体   English

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

[英]error C2146: syntax error : missing ';' before identifier 'ContextRecord'

i have a header file which contained all of the class' functions including code so the class didn't have a cpp file. 我有一个头文件,其中包含所有类的函数,包括代码,因此该类没有cpp文件。 everything worked. 一切顺利。 I added the cpp file and moved the function code over to that and now i get this error when compiling. 我添加了cpp文件并将功能代码移到了那里,现在我在编译时遇到了这个错误。 the header that im getting the error in ((x86)\\microsoft sdks\\windows\\v7.0a\\include\\winnt.h(6361)) isnt even included by the file that im changing. 我在((x86)\\ microsoft sdks \\ windows \\ v7.0a \\ include \\ winnt.h(6361))中获取错误的标题甚至不包含在即时更改的文件中。 does anyone know what the reason for this might be? 有谁知道这可能是什么原因? i can provide code i just don't know what would be helpful. 我可以提供代码我只是不知道什么是有用的。

the cpp file: 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;
}

the header: 标题:

#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

including windows.h at the top of the header file solved this issue. 包括头文件顶部的windows.h解决了这个问题。

Does the error also say PCONTEXT undefined ? 该错误是否也说PCONTEXT undefined

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

In reply to comment about unresolved external symbol : 回复有关unresolved external symbol评论:

That's because you didn't define Fisherman::SetFront in the cpp file. 那是因为你没有在cpp文件中定义Fisherman::SetFront

Whole code would be helpfull. 整个代码会有所帮助。 Did you remember obvious to give namespace to names of functions etc? 您是否记得明显将命名空间赋予函数名称等?

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

etc? 等等?

Fastest way would be reverting back to state when it worked, and not moving whole at once, but only one function at a time. 最快的方式是在它工作时恢复状态,而不是一次移动整个,但一次只能移动一个。 Then when problem would occure you could give us that specific code or try to fix it yourself. 然后,当问题发生时,您可以给我们特定的代码或尝试自己修复它。

It is very possible that there is just a missed ';', somewhere before this line. 在这一行之前的某个地方很可能只有一个错过的';'。

Double-check your code, remember that everything you define in a cpp file has to already be declared in your class definition. 仔细检查您的代码,记住您在cpp文件中定义的所有内容都必须已在类定义中声明。

I'd prefer to post a comment, but apparently I'm not allowed. 我更愿意发表评论,但显然我不被允许。

Anyway, as a simpler way to give us a feel of what you're trying to do, definatley post your code - it does not have to be exactly as you use, but should be a concise piece of generic code, highlighting how you are doing something. 无论如何,作为一种更简单的方式让我们感受到你想要做的事情,definatley发布你的代码 - 它不一定与你使用的完全一样,但应该是一个简洁的通用代码片段,突出你是怎样的做某事。 ( SSCCE ) If it really is a bug in how you typed it, it would be good to have your exact code, but put it on pastebin and provide a link so that this page doesn't end up with reams of code. SSCCE )如果它确实是你输入它的错误,最好有你的确切代码,但把它放在pastebin上并提供一个链接,这样这个页面就不会有大量的代码了。

EDIT: winnt.h apparently causes all sorts of problems: Weird compile error dealing with Winnt.h it is used to provide definitions for winAPI specific headers, as far as I know. 编辑: winnt.h显然会导致各种各样的问题: 奇怪的编译错误处理Winnt.h它用于提供winAPI特定标头的定义,据我所知。 One of the solutions proposed on that thread is to get the definitions from a different windows header before including whichever header requires those definitions. 在该线程上提出的解决方案之一是在包含需要这些定义的标头之前从不同的Windows标头获取定义。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误C2146:语法错误:缺少&#39;;&#39; 在标识符之前 - error C2146: syntax error : missing ';' before identifier 错误C2146:语法错误:在标识符&#39;A1&#39;之前缺少&#39;,&#39; - Error C2146: syntax error : missing ',' before identifier 'A1' 错误C2146:语法错误:缺少&#39;;&#39; 在标识符之前 - Error C2146: syntax error : missing ';' before identifier C ++错误1错误C2146:语法错误:缺少&#39;;&#39; 在标识符“记录”之前 - C++ Error 1 error C2146: syntax error: missing ';' before identifier 'records' 模板Fn指针错误C2146:语法错误:缺少&#39;;&#39; 在标识符之前 - Template Fn Pointer error C2146: syntax error : missing ';' before identifier 错误C2146:语法错误:在按功能传递地图时,在标识符mType之前缺少',' - error C2146: syntax error : missing ',' before identifier mType when passing a map by function 错误C2146:语法错误:缺少&#39;;&#39; 在标识符&#39;m_ball&#39;C ++之前 - error C2146: syntax error : missing ';' before identifier 'm_ball' C++, MFC VC ++错误C2146:语法错误:标识符&#39;pFirst&#39;之前缺少&#39;)&#39; - VC++ error C2146: syntax error : missing ')' before identifier 'pFirst' 错误C2146:语法错误:缺少&#39;;&#39; 在标识符“ g_App”之前 - error C2146: syntax error : missing ';' before identifier 'g_App' 错误C2146的可能原因:语法错误:缺少';'在标识符之前 - Possible reason for error C2146: syntax error : missing ';' before identifier
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM