1

我去编译我的程序的最新版本,令我恐惧的是 VS 给了我以下构建错误消息。当我单击错误消息让它带我到问题时,它带我到 ctype.h 头文件?

1>c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\ctype.h(22): error C2143: syntax error : missing ';' before 'string'
1>c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\ctype.h(22): error C2059: syntax error : 'string'
1>c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\ctype.h(22): error C2143: syntax error : missing ';' before '{'
1>c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\ctype.h(22): error C2447: '{' : missing function header (old-style formal list?)

现在我知道我还没有玩过 ctype.h。

自上次构建以来,我编辑的唯一文件甚至还没有进入主代码的入口点。

我将它们包括在下面。

BowlingPin.cpp

#include <vector>
#include "BowlingPin.h"
#include "Entity.h"
#include <iostream>
#include <GL/glut.h>
#include "NormalCalculator.h"


vector<GLfloat> pinVerts;
vector<GLfloat> pinNorms;
vector<GLubyte> pinInd;
//declare a normal calculator
NormalCalculator normCalc;



BowlingPin::BowlingPin(NormalCalculator::GLpoint pos, NormalCalculator::GLpoint vel) : Entity(pos, vel)
{
    height = 40;
    width = 10;

    //create a normal calculator for use in a bit
    normCalc = NormalCalculator();


    createBoundingArray();//create the bounding array
    createPinVectors();//create the vertices of the object


} 

void BowlingPin::createBoundingArray()
{
    topSphere.centerPos.y = height - (width/2);
    topSphere.centerPos.x = position.x;//give the hitsphere the passed positions x and z values
    topSphere.centerPos.z = position.z;
    topSphere.radius = width/2;

    baseSphere.centerPos.y = width/2;
    baseSphere.centerPos.x = position.x;
    baseSphere.centerPos.z = position.z;
    baseSphere.radius = width/2;

    boundingArray.push_back(topSphere); //push them into the bounding array
    boundingArray.push_back(baseSphere);
}

int BowlingPin::whatIsBeingTouched(hitSphere otherSphere)
{
    if(boundingSphereIsTouching(topSphere, otherSphere))
    {
        return 0;
    }
    else if(boundingSphereIsTouching(baseSphere, otherSphere))
    {
        return 1;
    }
    else 
    {
        cout<<"/nERROR: The Bounding Sphere is touching absolutely nothing."<<endl;
        return 9999; //throw in a bit of psychotic behaviour in there in case i don't notice
    }
}

/////WHERE YOU LEFT OFF: you have created functions for detecting what part of the pin was hit.
//////Next is probably creating a function for detecting what 
/////direction/velocity the pin was hit from and determining which direction it should fly off in.
/////Then comes the bitch. Learn how to matrix rotate and have control enough to keep the hit spheres
/////in place on the pins in order to maintain programatic control.
/////Add states e.g. Static, Falling, Fallen for pins, so that we can calculate what to do.

void BowlingPin::createPinVectors()
{
    GLfloat tempVerts[51] = 
    {
        //Bottom
        position.x, position.y, position.z-(width/3),//close
        position.x-(width/3), position.y, position.z,//left
        position.x, position.y, position.z+(width/3),//far
        position.x+(width/3), position.y, position.z,//right
        //2nd floor
        position.x, position.y+(height/4), position.z-(width/2),//close
        position.x-(width/2), position.y+(height/4), position.z,//left
        position.x, position.y+(height/4), position.z+(width/2),//far
        position.x+(width/2), position.y+(height/4), position.z,//right
        //3rd floor
        position.x, position.y+(height/2), position.z-(width/3),//close
        position.x-(width/3), position.y+(height/2), position.z,//left
        position.x, position.y+(height/2), position.z+(width/3),//far
        position.x+(width/3), position.y+(height/2), position.z,//right
        //4th floor
        position.x, position.y+(height/2)+(height/4), position.z-(width/4),//close
        position.x-(width/4), position.y+(height/2)+(height/4), position.z,//left
        position.x, position.y+(height/2)+(height/4), position.z+(width/4),//far
        position.x+(width/4), position.y+(height/2)+(height/4), position.z,//right
        //apex
        position.x, position.y+height, position.z//middle

    };

    //copy these into the vertices vector

    for(int i = 0; i<51; i++)
    {
        pinInd.push_back(tempVerts[i]);
        printf("/nAdded %f to the pin's vertex array", tempVerts[i]);
    }

    ///get us some indices

    GLubyte tempIndices[90] = 
    {
        0,1,2,//Base
        0,2,3,
        0,5,4,//bottom face 1
        1,5,4,
        1,6,5,//bottom face 2
        1,2,6,
        3,7,6,//bottom face 3
        2,3,6,
        0,4,3,//bopttom face 4
        4,7,3,
        ///////next level
        4,5,8,//l2 1
        5,9,8,
        5,10,9,//l2 2
        5,6,10,
        6,11,10,//l2 3
        6,7,11,
        4,8,11,//l2 4
        4,11,7,
        ///////lvl 3
        8,13,12,//l3 1
        8,9,13,
        9,14,13,//l3 2
        9,12,13,
        10,15,14,//l3 3
        10,11,15,
        11,12,15,//l3 4
        11,8,12,
        /////////crown
        12,13,16,
        13,14,16,
        14,15,16,
        15,12,16

    };

    //load these into the pinInds array

    for(int i = 0; i<90; i++)
    {
        pinInd.push_back(tempIndices[i]);
        printf("\nAdded %i to the pins Index array",tempIndices[i]);
    }

}

还有这个类的头文件

BowlingPin.h

#pragma once

#include "Entity.h"
#include "NormalCalculator.h"

class BowlingPin: public Entity
{

public: 
    BowlingPin(NormalCalculator::GLpoint pos, NormalCalculator::GLpoint vel);
    hitSphere topSphere; //the top hitSphere
    hitSphere baseSphere; //the bottom hitSphere
    int whatIsBeingTouched(hitSphere otherSphere); //when a collision is detected use this method to decide which of this pins spheres was hit. 0 = the top sphere and 1 = the bottom.
    NormalCalculator::GLpoint getNewVelocityFromImpactWith(NormalCalculator::GLpoint otherEntVel);


private:
    void createBoundingArray();//both creates (gives value to) the hitSpheres and adds them to the bounding array
    void rotatePin(GLfloat degrees); 
    int height;
    int width;

private:
    void createPinVectors();

}

有其他人知道这是什么类型的错误以及为什么会发生吗?

4

1 回答 1

7

您在 BowlingPin 课程的末尾缺少一个分号 :-)

当编译器展开#includeBowlingPin.h 的时候,它之后编译的下一段代码会触发 'expected semicolon' 错误;在这种情况下,它恰好出现在 ctype.h 中(必须通过iostream-- 注意 Entity.h 不会触发错误,即使它包含在 iostream 之前,因为 Entity.h 已经包含在 BowlingPin.h 中,并且它只编译一次,因为pragma once)。

于 2012-11-23T15:55:07.230 回答