我有以下問題:在我看來這個錯誤,當我編譯源代碼:「缺少類型說明INT假設」 C++問題
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
。
你有什麼包括? – 2011-12-17 21:50:05
這是什麼編譯器? – Omnifarious 2011-12-17 21:55:04