나는 다음과 같은 헤더 파일이 : 지금은 내 코드를 컴파일 할 때C에서 오류 ++ '형식의 이름이없는'
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stddef.h>
#include <GL/glew.h>
#include <GL/glfw.h>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <stdlib.h>
#include <vector>
class Sphere
{
public:
Sphere();
int count_sphere_vertices(int ,int, int);
Vertex* create_sphere(int ,int , int);
};
를 내가 얻을이 :
Sphere.h:18:3: error: ‘Vertex’ does not name a type
Sphere.cpp:48:1: error: ‘Vertex’ does not name a type
및
test_1.cpp: In function ‘int main()’:
test_1.cpp:318:38: error: ‘class Sphere’ has no member named ‘create_sphere’
무엇이
'꼭지점'은 유형을 지정하지 않습니다.
을 의미합니까? 그리고 왜 내가 어떻게해야합니까
내 Sphere.cpp이이 있기 때문에 '클래스 구체는'더 멤버 'create_sphere'
이름이 없다 :
//Calculating points for the sphere (the algorithm is implemented here)
Vertex* Sphere::create_sphere(int dtheta,int dphi, int no_vertices)
{
GLdouble x,y,z,x2,y2,z2;
GLdouble magnitude=0;
int n=-1;
int theta,phi;
const double PI = 3.1415926535897;
GLdouble DTOR = (PI/180);//degrees to radians
Vertex* sphere_vertices = new Vertex[no_vertices];
for (theta=-90;theta<=90-dtheta;theta+=dtheta) {
for (phi=0;phi<=360-dphi;phi+=dphi) {
//calculating Vertex 1
x = cos(theta*DTOR) * cos(phi*DTOR);
y = cos(theta*DTOR) * sin(phi*DTOR);
z = sin(theta*DTOR);
n+=1;
sphere_vertices[n].position[0] = x;
sphere_vertices[n].position[1] = y;
sphere_vertices[n].position[2] = z;
//calculating Vertex 2
x = cos((theta+dtheta)*DTOR) * cos(phi*DTOR);
y = cos((theta+dtheta)*DTOR) * sin(phi*DTOR);
z = sin((theta+dtheta)*DTOR);
n+=1;
sphere_vertices[n].position[0] = x;
sphere_vertices[n].position[1] = y;
sphere_vertices[n].position[2] = z;
//calculating Vertex 3
x = cos((theta+dtheta)*DTOR) * cos((phi+dphi)*DTOR);
y = cos((theta+dtheta)*DTOR) * sin((phi+dphi)*DTOR);
z = sin((theta+dtheta)*DTOR);
n+=1;
sphere_vertices[n].position[0] = x;
sphere_vertices[n].position[1] = y;
sphere_vertices[n].position[2] = z;
//adding Vertex_1 again to divide the Quad into 2 triangles so it can be later filled with triangles!!!
//adding Vertex 1 again!
x = cos(theta*DTOR) * cos(phi*DTOR);
y = cos(theta*DTOR) * sin(phi*DTOR);
z = sin(theta*DTOR);
n+=1;
sphere_vertices[n].position[0] = x;
sphere_vertices[n].position[1] = y;
sphere_vertices[n].position[2] = z;
if (theta > -90 && theta < 90) {
//calculating Vertex 4
x = cos(theta*DTOR) * cos((phi+dphi)*DTOR);
y = cos(theta*DTOR) * sin((phi+dphi)*DTOR);
z = sin(theta*DTOR);
n+=1;
sphere_vertices[n].position[0] = x;
sphere_vertices[n].position[1] = y;
sphere_vertices[n].position[2] = z;
}
}
}
//Setting the color
for(int i=0; i<no_vertices; i+=1)
{
sphere_vertices[i].color[0] = 1;
sphere_vertices[i].color[1] = 0;
sphere_vertices[i].color[2] = 0;
}
printf("%d >> \n", n);
return sphere_vertices;
}
Thansk
편집 : 내 test_1.cpp "main"메서드가있는 곳에 포함되어 있습니다.
#include "Sphere.h"
#include "Terrain.h"
using namespace std;
//Vertex Structure
struct Vertex {
GLdouble position[3];
GLfloat color[3];
GLfloat texture[2];
};
그때 나는이 파일 Sphere.h의 정점을 포함하는 가정하고 어떻게
sphere_vertices_final = planet_1->create_sphere(5,5,no_sphere_vertices);
같은 구체를 생성?
'Vertex'라는 선언이 누락되었습니다. 어쩌면 헤더를'#include '하는 것을 잊었을 까? 선언이 같은 파일에 있다면, * Sphere의 정의 앞에 * 선언을 넣어야합니다. 다른 오류는 첫 번째 오류의 눈덩이 효과에 불과합니다. –
헤더? 꼭지점은 구조 변수 일뿐입니다. 어떻게 포함시켜야합니까? –
별도의 머리글에 없으면 '구형'정의보다 위에 있어야합니다. –