저는 C++과 Open GL에 매우 익숙하며 장면에 3D 객체를 표시하려고했습니다. 하나는 괜찮 았지만 두 번째 코드를 변경하려고 할 때 카메라 위치를 나타내는 HUD 텍스트 관련 코드가 오류를 내기 시작했습니다. 위의 오류가 표시되며 sstream 파일 (#include)에있는 것 같습니다. 나는 주변을 검색하고 도움을 청하려고 노력했지만 도움이되는 것은 없으며 이해합니다. #include 줄과 그 코드를 사용하는 코드를 주석으로 처리하면 비슷한 오류 메시지가 나타납니다. "오류 C2143 : 구문 오류 : 누락 된 ';' 내 main.cpp 파일에서 'using'을 사용하기 전에.오류 C2143 : 구문 오류 : ';'가 없습니다. before 'namespace'
저는 Visual Studio 2010을 실행 중입니다. 모든 작업을 다시 시작하고 코드를 새 프로젝트에 복사 해 보았습니다. 도움말 크게 감사하겠습니다.
#include <Windows.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include "glut.h"
#include "SceneObject.h"
#include <fstream>
#include <sstream>
#include <iostream>
#include <string>
//#include <cmath>
//#include <limits>
//#include <cstdlib>
using namespace std;
...
stringstream ss;
ss << "Camera (" << cam.pos.x << ", " << cam.pos.y << ", " << cam.pos.z << ")";
glClear(GL_DEPTH_BUFFER_BIT);
outputText(-1.0, 0.5, ss.str());
...
#ifndef SCENEOBJECT_H
#define SCENEOBJECT_H
#include <string>
#include <iostream>
#include <fstream>
using namespace std;
struct point3D {
float x;
float y;
float z;
};
struct colour{
float r;
float g;
float b;
};
struct tri {
int a;
int b;
int c;
};
class SceneObject {
private:
int NUM_VERTS;
int NUM_COL;
int NUM_TRI;
point3D * vertices;
colour * colours;
tri * indices;
void drawTriangle(int a, int b, int c);
public:
SceneObject(const string fName) {
read_file(fName);
}
void drawShape()
{
// DO SOMETHING HERE
}
int read_file (const string fileName)
{
ifstream inFile;
inFile.open(fileName);
if (!inFile.good())
{
cerr << "Can't open file" << endl;
NUM_TRI = 0;
return 1;
}
//inFile >> shapeID;
inFile >> NUM_VERTS;
vertices = new point3D[NUM_VERTS];
for (int i=0; i < NUM_VERTS; i++)
{
inFile >> vertices[i].x;
inFile >> vertices[i].y;
inFile >> vertices[i].z;
}
inFile >> NUM_COL;
//inFile >> randomCol;
colours = new colour[NUM_COL];
/*if (randomCol == 'y')
{
for (int i=0; i < NUM_COL; i++)
{
colours[i].r = ((float) rand()/(RAND_MAX+1));
colours[i].g = ((float) rand()/(RAND_MAX+1));
colours[i].b = ((float) rand()/(RAND_MAX+1));
}
}
else if (randomCol == 'n')
{*/
for (int i=0; i < NUM_COL; i++)
{
inFile >> colours[i].r;
inFile >> colours[i].g;
inFile >> colours[i].b;
}
//}
inFile >> NUM_TRI;
indices = new tri[NUM_TRI];
for (int i=0; i < NUM_TRI; i++)
{
inFile >> indices[i].a;
inFile >> indices[i].b;
inFile >> indices[i].c;
}
inFile.close();
return 0;
}
}
#endif
내가 코드를 변경하지 않은 내가 아는까지, 거기에 세미콜론이있다 그럴거야. 5 년 동안 프로그래밍을 해왔 던 나의 친구조차 이것을 해결할 수 없었습니다. 필요한 경우 다른 특정 코드를 포함합니다. 그리고 제가 C++과 OpenGL에 대해 새로운 것을 말했을 때 저는 정말 아주 새롭습니다. 이것은 내 첫 번째 게시물이기도합니다. 나는 결국 거기에 도착할 것이다.
코드를 설명하는 대신 단순히 의심스러운 코드를 모두 표시하여 제거하십시오. 질문과 코드를 수정하십시오. 보통이 오류는'struct' 나'class'의 끝에';'을 잊어 버렸을 때 발생합니다. –
글쎄, 당신은 어딘가에, 아마도 클래스 선언의 마지막에 – Mat
또는 더 구체적으로 * 네임 스페이스 선언 앞에 *가 없습니다. –