I have a piece of code and some errors and warnings, I could not understand why they occur. Could you give me your advice?
The first:
#pragma once
#include "Vector3.h"
#include <vector>
#include <GL/glew.h>
class BoundingSphere
{
public:
float radius;
Vector3 center;
BoundingSphere(float radius, Vector3 center) : radius(radius),center(center) {};
BoundingSphere() {};
};
class TriangleFace;
class MeshVertex
{
private:
Vector3 position;
std::vector<TriangleFace *> faces;
Vector3 normal;
bool normalUpdateNeeded;
public:
unsigned int index;
MeshVertex(void);
MeshVertex(Vector3 position);
~MeshVertex(void);
Vector3 &getPos() {return position;};
void addFace(TriangleFace *face);
const std::vector<TriangleFace*>& getFaces() {return faces; };
Vector3 getNormal();
void setPos(Vector3 & pos) {position = pos; }
bool isSurfaceParticle() {return faces.size()>0;}
void updateNormal();
};
class TriangleFace
{
private:
Vector3 normal;
bool normalUpdateNeeded;
public:
MeshVertex* particles[3];
TriangleFace(void);
TriangleFace(MeshVertex *p1, MeshVertex *p2, MeshVertex *p3);
MeshVertex& operator[](int i) { return *(particles[i]); }
Vector3 getNormal();
~TriangleFace(void);
void updateNormal();
};
class TriangleMesh
{
protected:
std::vector<MeshVertex> particles;
std::vector<TriangleFace> faces;
public:
TriangleMesh(string filename);
~TriangleMesh(void);
void reserveNumberOfFaces(unsigned int n) { faces.reserve(n); };
void addFace(TriangleFace &f) {faces.push_back(f);};
void addFace(MeshVertex *p1, MeshVertex *p2, MeshVertex *p3) {faces.push_back(TriangleFace(p1,p2,p3));};
std::vector<TriangleFace>& getFaces() {return faces;};
std::vector<MeshVertex>& getParticles() { return particles; };
void updateNormals();
BoundingSphere getBoundingSphere();
};
class RenderTriangleMesh
{
private:
TriangleMesh &m;
GLuint vboid[2];
GLfloat *vertices;
GLfloat *normals;
public:
RenderTriangleMesh(TriangleMesh &m);
void draw();
private:
void generateVBOs();
void updateVBOs();
};
Errors:
error C2220: warning treated as error – no ‘object’ file generated
warning C4512: ‘RenderTriangleMesh’ : assignment operator could not be generated
And the other:
virtual short SimpleAddOK(const GeneralMatrix* gm) { return 0; }
error :
error C2220: warning treated as error – no ‘object’ file generated
warning C4100: ‘gm’ : unreferenced formal parameter
The first is saying that the compiler could not generate an assignment operator. This happens because of your reference member, as references cannot be reseated:
You can silence the warning by explicitly disabling it yourself:
That’s an old trick to make the assignment operator unusable, but stops the compiler from generating it.
In C++11, you can do this:
which is more explicit and much less hacky.
The other is because you never used your argument, which can often be an error in program logic. You should probably remove its name if you don’t use it:
Personally I delete it completely. Others do this:
It’s sometimes wrapped in a macro called
USE:I consider these inferior to simply deleting the name, because if the warning is actually correct (that is, you do have a flaw in your program and aren’t seeing it), you’re masking the warning, defeating the purpose.
Warnings should always be fixed, not silenced.