I have the following problem: This error appeared to me, when I compiled the source code:
error C4430: missing type specifier - int assumed
This error occurs when a variable is not initialized with any type (like a integer, float or any custom type of object). But, I have a type initialized and it’s not recognizable, although I have more classes, which are similarly built like the trouble one, and they’re running fine.
So, my problematic class is the following one:
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;}
};
An example of a working class:
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;}
};
Finally, the code fragment where the errors occur:
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(); }
};
Any ideas about how to correct it?
EDIT: My includes are:
#include "Material.h" //custom class
#include "Texture.h" //custom class
#include <iostream>
The compiler is Visual C++ 2010.
Aside from a really bad design, there are no actual errors in the code you’ve shown. My guess is that the error is in code you haven’t shown us.
My personal guess is that either
Rectangleorrectsomehow don’t mean what you expect them to mean at the point you’re using them. Perhaps someone has been playing tricks with the preprocessor.I’m absolutely certain that there is no erroneous code of any kind in what you’ve presented here. I’ve edited your code lightly, and it compiles perfectly: