"Missing type specifier int assumed" C++问题
"Missing type specifier int assumed" C++ Issue
我有以下问题:当我编译源代码时,出现了这个错误:
error C4430: missing type specifier - int assumed
当变量没有使用任何类型(如整数、浮点数或任何自定义类型的对象)初始化时,会发生此错误。但是,我有一个初始化的类型,它是不可识别的,尽管我有更多的类,这些类的构建类似于麻烦的那个,它们运行得很好。
那么,我的问题类是下面这个:
class Rectangle
{
float x1, y1, x2, y2;
bool created;
public:
Rectangle() { created = false;}
Rectangle(float x1, float y1, float x2, float y2);
~Rectangle() {}
bool isCreated() { return created;}
void setCreated( bool c) { created = c;}
float getX1() { return x1;}
float getX2() { return x2;}
float getY1() { return y1;}
float getY2() { return y2;}
};
一个工人阶级的例子:
class Triangle
{
private:
vector<float> x, y, z;
bool created;
public:
Triangle() { created = false;}
Triangle(vector<float> x, vector<float> y, vector<float> z);
~Triangle() {}
bool isCreated() { return created;}
void setCreated( bool c) { created = c;}
vector<float> getX() { return x;}
vector<float> getY() { return y;}
vector<float> getZ() { return z;}
};
最后,出现错误的代码片段:
class Primitive
{
private:
string index;
Material mat;
Texture text;
int count;
Rectangle rect; //error detected in this line
Triangle tri;
Cylinder cyl;
Sphere sph;
Torus tor;
public:
Primitive() {count = 0;}
Primitive(string id, Material mt, Texture tx);
~Primitive(void);
string getIndex() { return index;}
Material getMaterial() { return mat;}
Texture getTexture() { return text;}
void addRectangle(float x1, float y1, float x2, float y2); //error detected in this line
Rectangle getRectangle() { if(rect.isCreated()) return rect; else return Rectangle(); } //error detected in this line
void addTriangle(float x1, float x2, float x3, float y1, float y2, float y3, float z1, float z2, float z3);
Triangle getTriangle() { if(tri.isCreated()) return tri; else return Triangle(); }
void addCylinder(float bs, float tp, float hei, int sli, int stac);
Cylinder getCylinder() { if(cyl.isCreated()) return cyl; else return Cylinder(); }
void addSphere(float rad, int sli, int stac);
Sphere getSphere() { if(sph.isCreated()) return sph; else return Sphere(); }
void addTorus(float in, float out, int sli, int loo);
Torus getTorus() { if(tor.isCreated()) return tor; else return Torus(); }
};
有什么好主意吗?
编辑:我的包括:
#include "Material.h" //custom class
#include "Texture.h" //custom class
#include <iostream>
编译器是Visual C++ 2010
除了非常糟糕的设计之外,您所展示的代码中并没有实际的错误。我猜错误出在你没有给我们看的代码里。
我个人的猜测是,Rectangle
或rect
在某种程度上并不意味着你在使用它们时期望它们的意思。也许有人在预处理器上耍花招。
我绝对肯定你在这里展示的代码中没有任何错误。我稍微编辑了一下你的代码,它可以完美地编译:
#include <string>
#include <vector>
class Rectangle
{
float x1, y1, x2, y2;
bool created;
public:
Rectangle() { created = false;}
Rectangle(float x1, float y1, float x2, float y2);
~Rectangle() {}
bool isCreated() { return created;}
void setCreated( bool c) { created = c;}
float getX1() { return x1;}
float getX2() { return x2;}
float getY1() { return y1;}
float getY2() { return y2;}
};
class Triangle
{
private:
::std::vector<float> x, y, z;
bool created;
public:
Triangle() { created = false;}
Triangle(::std::vector<float> x, ::std::vector<float> y, ::std::vector<float> z);
~Triangle() {}
bool isCreated() { return created;}
void setCreated( bool c) { created = c;}
::std::vector<float> getX() { return x;}
::std::vector<float> getY() { return y;}
::std::vector<float> getZ() { return z;}
};
class Primitive
{
private:
::std::string index;
// Material mat;
// Texture text;
int count;
Rectangle rect; //error detected in this line
Triangle tri;
// Cylinder cyl;
// Sphere sph;
// Torus tor;
public:
Primitive() {count = 0;}
// Primitive(::std::string id, Material mt, Texture tx);
~Primitive(void);
::std::string getIndex() { return index;}
// Material getMaterial() { return mat;}
// Texture getTexture() { return text;}
void addRectangle(float x1, float y1, float x2, float y2); //error detected in this line
Rectangle getRectangle() { if(rect.isCreated()) return rect; else return Rectangle(); } //error detected in this line
void addTriangle(float x1, float x2, float x3, float y1, float y2, float y3, float z1, float z2, float z3);
Triangle getTriangle() { if(tri.isCreated()) return tri; else return Triangle(); }
// void addCylinder(float bs, float tp, float hei, int sli, int stac);
// Cylinder getCylinder() { if(cyl.isCreated()) return cyl; else return Cylinder(); }
// void addSphere(float rad, int sli, int stac);
// Sphere getSphere() { if(sph.isCreated()) return sph; else return Sphere(); }
// void addTorus(float in, float out, int sli, int loo);
// Torus getTorus() { if(tor.isCreated()) return tor; else return Torus(); }
};
我怀疑在翻译单元中Primitive
之前没有定义Rectangle
类
相关文章:
- 警告处理为错误这里有什么问题
- 最小硬币更换问题(自上而下方法)
- 为"adjacent"变量赋值时出现问题
- 我的神经网络不起作用 [XOR 问题]
- 在Ubuntu 16.04上安装Cilk时出现问题
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 编译包含字符串的代码时遇到问题
- Project Euler问题4的错误解决方案
- 问题:什么是QAbstractItemView::NoEditTriggers的反面
- 在编译C++代码(具有dlib和opencv)到WASM时面临问题
- 在进程中对同一管道进行读取和写入时C++管道出现问题
- 静态数据成员的问题-修复链接错误会导致编译器错误
- C++ 雷神库 - 使用资源加载器类时出现问题(不命名类型)
- 一个关于在C++中重载布尔运算符的问题
- 首要问题的答案让值班员搞错了
- setlocale的C++土耳其字符串问题
- 如何重构类层次结构以避免菱形问题
- 基于boost的程序的静态链接——zlib问题
- C++格式化输出问题
- 使用mongocxx驱动程序时包含头文件问题