C++命名空间错误error C2653: 'create' : is not a class or namespace name
头文件:#ifdefstruc_h#definestruc_hclasscreate{public:voiddramobj();};#endifcpp文件:#includ...
头文件:
#ifdef struc_h
#define struc_h
class create
{
public:
void dramobj();
};
#endif
cpp文件:
#include <windows.h>
#include <stdio.h>
#include <gl/gl.h>
#include "struct.h"
typedef struct
{
float x,y,z,p;
}vertex;
typedef struct
{
int verts;
vertex *points;
}object;
void objallocate(object *k,int n) // 申请内存空间
{
k->points=(vertex*)malloc(sizeof(vertex)*n);
}
void objfree(object *k)
{
free(k->points);
}
object m;
void readstr(FILE *f,char *strings)
{
do
{
fgets(strings, 255, f);
} while ((strings[0] == '/') || (strings[0] == '\n'));
return;
}
void objload(char *name,object *k)
{
int ver;
float rx,ry,rz,rp;
FILE *filein;
char oneline[255];
filein = fopen("in1t.txt", "rt");
readstr(filein,oneline);
sscanf(oneline, "Vertices: %d\n", &ver);
k->verts=ver;
objallocate(k,ver); // 申请内存空间
for (int i=0;i<ver;i++)
{
readstr(filein,oneline);
sscanf(oneline, "%f %f %f", &rx, &ry, &rz,&rp);
k->points[i].x = rx;
k->points[i].y = ry;
k->points[i].z = rz;
k->points[i].p=rz;
}
fclose(filein);
}
void create::dramobj ()
{
GLfloat tx,ty,tz,tp;
vertex q;
objload("in5t",&m);//导入模型
glBegin (GL_POINTS);
for(int s=0;s<m.verts;s++)
{
tx=q.x;
ty=q.y;
tz=q.z;
tp=q.p;
glColor3f(tp/350,tp/350,tp/350);
glVertex3f (tx,ty,tz);
}
glEnd();
}不知道是哪里错了,老是提示命名空间错误,求高手帮忙 展开
#ifdef struc_h
#define struc_h
class create
{
public:
void dramobj();
};
#endif
cpp文件:
#include <windows.h>
#include <stdio.h>
#include <gl/gl.h>
#include "struct.h"
typedef struct
{
float x,y,z,p;
}vertex;
typedef struct
{
int verts;
vertex *points;
}object;
void objallocate(object *k,int n) // 申请内存空间
{
k->points=(vertex*)malloc(sizeof(vertex)*n);
}
void objfree(object *k)
{
free(k->points);
}
object m;
void readstr(FILE *f,char *strings)
{
do
{
fgets(strings, 255, f);
} while ((strings[0] == '/') || (strings[0] == '\n'));
return;
}
void objload(char *name,object *k)
{
int ver;
float rx,ry,rz,rp;
FILE *filein;
char oneline[255];
filein = fopen("in1t.txt", "rt");
readstr(filein,oneline);
sscanf(oneline, "Vertices: %d\n", &ver);
k->verts=ver;
objallocate(k,ver); // 申请内存空间
for (int i=0;i<ver;i++)
{
readstr(filein,oneline);
sscanf(oneline, "%f %f %f", &rx, &ry, &rz,&rp);
k->points[i].x = rx;
k->points[i].y = ry;
k->points[i].z = rz;
k->points[i].p=rz;
}
fclose(filein);
}
void create::dramobj ()
{
GLfloat tx,ty,tz,tp;
vertex q;
objload("in5t",&m);//导入模型
glBegin (GL_POINTS);
for(int s=0;s<m.verts;s++)
{
tx=q.x;
ty=q.y;
tz=q.z;
tp=q.p;
glColor3f(tp/350,tp/350,tp/350);
glVertex3f (tx,ty,tz);
}
glEnd();
}不知道是哪里错了,老是提示命名空间错误,求高手帮忙 展开
3个回答
展开全部
修改:
#ifndef struc_h
#define struc_h
class create
{
public:
void dramobj();
};
#endif
----------
头文件防止重定义作法:
#ifndef _some
#define _some
//...
#endif
#ifndef struc_h
#define struc_h
class create
{
public:
void dramobj();
};
#endif
----------
头文件防止重定义作法:
#ifndef _some
#define _some
//...
#endif
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
cpp文件有问题
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询