VS告诉我ctype.h中存在构建错误

时间:2012-11-23 15:52:52

标签: c++ visual-studio-2010 opengl

我去编译我的程序的最新版本,令我惊恐的是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();

}

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

1 个答案:

答案 0 :(得分:7)

你在BowlingPin课程结束时遗漏了一个分号: - )

当编译器扩展BowlingPin.h的#include时,在它之后编译的下一段代码将触发'预期的分号'错误;在这种情况下,它碰巧出现在ctype.h中(必须通过iostream包含 - 注意Entity.h不会触发错误,即使它在iostream之前包含,因为Entity.h已经包含在BowlingPin.h,由于pragma once),它只编译了一次。