F
Francesco Gallarotti
Can any of you help with this? Pretty much all the errors I have belong to 2
different categories:
1) error C2872: ambiguous symbols
2) error C2662: cannot convert 'this' pointer from 'const class Vertex' to
'class Vertex &'
Let's see them:
f:\my school\cse528\showdxf\vertex.h(9) : error C2872: 'ostream' : ambiguous
symbol
f:\my school\cse528\showdxf\vertex.h(9) : error C2872: 'ostream' : ambiguous
symbol
f:\my school\cse528\showdxf\triangle.h(9) : error C2872: 'ostream' :
ambiguous symbol
f:\my school\cse528\showdxf\triangle.h(9) : error C2872: 'ostream' :
ambiguous symbol
f:\my school\cse528\showdxf\edge.h(12) : error C2872: 'ostream' : ambiguous
symbol
f:\my school\cse528\showdxf\edge.h(12) : error C2872: 'ostream' : ambiguous
symbol
f:\my school\cse528\showdxf\dxfparser.h(34) : error C2872: 'ifstream' :
ambiguous symbol
f:\my school\cse528\showdxf\dxfparser.h(35) : error C2872: 'ifstream' :
ambiguous symbol
f:\my school\cse528\showdxf\dxfparser.h(36) : error C2872: 'ifstream' :
ambiguous symbol
f:\my school\cse528\showdxf\dxfparser.h(37) : error C2872: 'ifstream' :
ambiguous symbol
f:\my school\cse528\showdxf\dxfparser.h(39) : error C2872: 'ifstream' :
ambiguous symbol
f:\my school\cse528\showdxf\drawdxf.cpp(505) : error C2872: 'cout' :
ambiguous symbol
f:\my school\cse528\showdxf\drawdxf.cpp(525) : error C2872: 'cout' :
ambiguous symbol
where for example:
#ifndef FG_VERTEX
#define FG_VERTEX
#include <iostream>
using namespace std;
class Vertex {
friend ostream &operator<<(ostream&, const Vertex&); <<<<<<<<< line 9
public:
Vertex(float vx, float vy, float vz);
~Vertex() { }; // default destructor
float getX(void) {return x;}; // returns vertex X coordinate
float getY(void) {return y;}; // returns vertex Y coordinate
float getZ(void) {return z;}; // returns vertex Z coordinate
void set(float newX, float newY, float newZ);
bool operator<(const Vertex& v) const;
bool operator==(const Vertex& v) const;
private:
float x,y,z;
};
#endif
and again:
#ifndef FG_DXF_PARSER
#define FG_DXF_PARSER
#include <fstream.h>
#include "model.h"
class DXFParser {
public:
void read_and_build(char *filename, Model *model);
private:
DXFSection getSection(ifstream is);
void readFace(ifstream is, Model *model);
void readPolyline(ifstream is, Model *model);
float getFloat(ifstream is);
void showError(void);
bool skipToHeader(ifstream is, char *header);
void trim(char *str, char *trimmed);
};
#endif
and let's see an example of the error C2662:
f:\my school\cse528\showdxf\vertex.cpp(17) : error C2662: 'getX' : cannot
convert 'this' pointer from 'const class Vertex' to 'class Vertex &'
Conversion loses qualifiers
f:\my school\cse528\showdxf\vertex.cpp(17) : error C2662: 'getY' : cannot
convert 'this' pointer from 'const class Vertex' to 'class Vertex &'
Conversion loses qualifiers
f:\my school\cse528\showdxf\vertex.cpp(17) : error C2662: 'getZ' : cannot
convert 'this' pointer from 'const class Vertex' to 'class Vertex &'
Conversion loses qualifiers
here is the vertex.cpp code:
#include <iostream>
#include "vertex.h"
Vertex::Vertex(float vx, float vy, float vz) {
x = vx; y = vy; z = vz;
}; // default constructor
void Vertex::set(float newX, float newY, float newZ) {
x = newX; y = newY; z = newZ;
};
ostream &operator<<(ostream& out, const Vertex& vertex) {
out << "(" << vertex.getX() << "," << vertex.getY() << "," <<
vertex.getZ() << ")";
return out;
}; // for printing
bool Vertex:perator <(const Vertex& v) const {
if(x<v.x) return true;
else if(x==v.x && y<v.y) return true;
else if(x==v.x && y==v.y && z<v.z) return true;
return false;
};
bool Vertex:perator ==(const Vertex& v) const {
return (x==v.x && y==v.y && z==v.z);
};
Any idea? I am getting really confused here! The only thing that makes me
happy here is that maybe somebody out there knows the solution to this
frustrating situation....
NOTE: the errors C2662 go away of I remove the const from the operator<<
definition, but i don't even know if this is correct overloading now
(Deitel's book shows "const" in it)
different categories:
1) error C2872: ambiguous symbols
2) error C2662: cannot convert 'this' pointer from 'const class Vertex' to
'class Vertex &'
Let's see them:
f:\my school\cse528\showdxf\vertex.h(9) : error C2872: 'ostream' : ambiguous
symbol
f:\my school\cse528\showdxf\vertex.h(9) : error C2872: 'ostream' : ambiguous
symbol
f:\my school\cse528\showdxf\triangle.h(9) : error C2872: 'ostream' :
ambiguous symbol
f:\my school\cse528\showdxf\triangle.h(9) : error C2872: 'ostream' :
ambiguous symbol
f:\my school\cse528\showdxf\edge.h(12) : error C2872: 'ostream' : ambiguous
symbol
f:\my school\cse528\showdxf\edge.h(12) : error C2872: 'ostream' : ambiguous
symbol
f:\my school\cse528\showdxf\dxfparser.h(34) : error C2872: 'ifstream' :
ambiguous symbol
f:\my school\cse528\showdxf\dxfparser.h(35) : error C2872: 'ifstream' :
ambiguous symbol
f:\my school\cse528\showdxf\dxfparser.h(36) : error C2872: 'ifstream' :
ambiguous symbol
f:\my school\cse528\showdxf\dxfparser.h(37) : error C2872: 'ifstream' :
ambiguous symbol
f:\my school\cse528\showdxf\dxfparser.h(39) : error C2872: 'ifstream' :
ambiguous symbol
f:\my school\cse528\showdxf\drawdxf.cpp(505) : error C2872: 'cout' :
ambiguous symbol
f:\my school\cse528\showdxf\drawdxf.cpp(525) : error C2872: 'cout' :
ambiguous symbol
where for example:
#ifndef FG_VERTEX
#define FG_VERTEX
#include <iostream>
using namespace std;
class Vertex {
friend ostream &operator<<(ostream&, const Vertex&); <<<<<<<<< line 9
public:
Vertex(float vx, float vy, float vz);
~Vertex() { }; // default destructor
float getX(void) {return x;}; // returns vertex X coordinate
float getY(void) {return y;}; // returns vertex Y coordinate
float getZ(void) {return z;}; // returns vertex Z coordinate
void set(float newX, float newY, float newZ);
bool operator<(const Vertex& v) const;
bool operator==(const Vertex& v) const;
private:
float x,y,z;
};
#endif
and again:
#ifndef FG_DXF_PARSER
#define FG_DXF_PARSER
#include <fstream.h>
#include "model.h"
class DXFParser {
public:
void read_and_build(char *filename, Model *model);
private:
DXFSection getSection(ifstream is);
void readFace(ifstream is, Model *model);
void readPolyline(ifstream is, Model *model);
float getFloat(ifstream is);
void showError(void);
bool skipToHeader(ifstream is, char *header);
void trim(char *str, char *trimmed);
};
#endif
and let's see an example of the error C2662:
f:\my school\cse528\showdxf\vertex.cpp(17) : error C2662: 'getX' : cannot
convert 'this' pointer from 'const class Vertex' to 'class Vertex &'
Conversion loses qualifiers
f:\my school\cse528\showdxf\vertex.cpp(17) : error C2662: 'getY' : cannot
convert 'this' pointer from 'const class Vertex' to 'class Vertex &'
Conversion loses qualifiers
f:\my school\cse528\showdxf\vertex.cpp(17) : error C2662: 'getZ' : cannot
convert 'this' pointer from 'const class Vertex' to 'class Vertex &'
Conversion loses qualifiers
here is the vertex.cpp code:
#include <iostream>
#include "vertex.h"
Vertex::Vertex(float vx, float vy, float vz) {
x = vx; y = vy; z = vz;
}; // default constructor
void Vertex::set(float newX, float newY, float newZ) {
x = newX; y = newY; z = newZ;
};
ostream &operator<<(ostream& out, const Vertex& vertex) {
out << "(" << vertex.getX() << "," << vertex.getY() << "," <<
vertex.getZ() << ")";
return out;
}; // for printing
bool Vertex:perator <(const Vertex& v) const {
if(x<v.x) return true;
else if(x==v.x && y<v.y) return true;
else if(x==v.x && y==v.y && z<v.z) return true;
return false;
};
bool Vertex:perator ==(const Vertex& v) const {
return (x==v.x && y==v.y && z==v.z);
};
Any idea? I am getting really confused here! The only thing that makes me
happy here is that maybe somebody out there knows the solution to this
frustrating situation....
NOTE: the errors C2662 go away of I remove the const from the operator<<
definition, but i don't even know if this is correct overloading now
(Deitel's book shows "const" in it)