473,382 Members | 1,423 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

namespace? include errors??

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::operator <(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::operator ==(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)
Jul 19 '05 #1
10 4514
WW
Francesco Gallarotti wrote:
class Vertex {
friend ostream &operator<<(ostream&, const Vertex&); <<<<<<<<<
You need to qualify with std:: here.
friend std::ostream &operator<<(std::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


float getX(void) const {return x;};
float getY(void) const {return y;};
float getZ(void) const {return z;};

Make them const. They don't change the object.
--
WW aka Attila
Jul 19 '05 #2
On Mon, 06 Oct 2003 13:57:34 GMT, "Francesco Gallarotti"
<ga********@hotmail.com> wrote:
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 &'

where for example:

#ifndef FG_VERTEX
#define FG_VERTEX
#include <iostream>
using namespace std;
Delete the above line! Never put "using namespace std" in a header,
since it produces exactly the problems you are seeing.
class Vertex {
friend ostream &operator<<(ostream&, const Vertex&); <<<<<<<<< line 9
friend std::ostream &operator<<(std::ostream&, const Vertex&);

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);
float getX(void) const {return x;}; // returns vertex X coordinate
float getY(void) const {return y;}; // returns vertex Y coordinate
float getZ(void) const {return z;}; // returns vertex Z coordinate

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>


Why the legacy header?

Tom
Jul 19 '05 #3
"WW" <wo***@freemail.hu> writes:
Francesco Gallarotti wrote:
class Vertex {
friend ostream &operator<<(ostream&, const Vertex&); <<<<<<<<<


You need to qualify with std:: here.
friend std::ostream &operator<<(std::ostream&, const Vertex&);


No, he doesn't - he has a

using namespace std;

just before the declaration of class Vertex.
To the OP: NEVER put using directives or declarations in header
files.

kind regards
frank

--
Frank Schmitt
4SC AG phone: +49 89 700763-0
e-mail: frankNO DOT SPAMschmitt AT 4sc DOT com
Jul 19 '05 #4
Frank Schmitt wrote:
"WW" <wo***@freemail.hu> writes:
Francesco Gallarotti wrote:
class Vertex {
friend ostream &operator<<(ostream&, const Vertex&); <<<<<<<<<


You need to qualify with std:: here.
friend std::ostream &operator<<(std::ostream&, const Vertex&);


No, he doesn't - he has a

using namespace std;

just before the declaration of class Vertex.
To the OP: NEVER put using directives or declarations in header
files.


IIRC a friend declaration does not pick up names from a using directive. I
might be wrong. If you have chapter and verse I can be easily convinced.
:-)

--
Attila aka WW
Jul 19 '05 #5
"Attila Feher" <at**********@lmf.ericsson.se> writes:
Frank Schmitt wrote:
"WW" <wo***@freemail.hu> writes:
Francesco Gallarotti wrote:
class Vertex {
friend ostream &operator<<(ostream&, const Vertex&); <<<<<<<<<

You need to qualify with std:: here.
friend std::ostream &operator<<(std::ostream&, const Vertex&);


No, he doesn't - he has a

using namespace std;

just before the declaration of class Vertex.
To the OP: NEVER put using directives or declarations in header
files.


IIRC a friend declaration does not pick up names from a using directive. I
might be wrong. If you have chapter and verse I can be easily convinced.
:-)


Aehm. You got me here - I honestly don't know whether a friend declaration
is different from a "normal" declaration regarding this ;-)
(damn, I *really* have to get a copy of the standard)

kind regards
frank

--
Frank Schmitt
4SC AG phone: +49 89 700763-0
e-mail: frankNO DOT SPAMschmitt AT 4sc DOT com
Jul 19 '05 #6
Frank Schmitt wrote:
[SNIP]
Aehm. You got me here - I honestly don't know whether a friend
declaration is different from a "normal" declaration regarding this
;-) (damn, I *really* have to get a copy of the standard)


Ahh. I was hoping you will do the job. :-) I do not remember this exactly
either. I recall someone telling it does not pick up names from other
namespaces. Actually friend declarations are veeery interesting beasts.
Herb Sutter has some pretty damn good presentation(s) about it.

--
Attila aka WW
Jul 19 '05 #7
Attila Feher wrote:
Frank Schmitt wrote:
[SNIP]
Aehm. You got me here - I honestly don't know whether a friend
declaration is different from a "normal" declaration regarding this
;-) (damn, I *really* have to get a copy of the standard)


Ahh. I was hoping you will do the job. :-) I do not remember this
exactly either. I recall someone telling it does not pick up names
from other namespaces.


I mean from using directives. Using declarations were (IIRC) told to be
different.

--
Attila aka WW
Jul 19 '05 #8
"Attila Feher" <at**********@lmf.ericsson.se> writes:
Attila Feher wrote:
Frank Schmitt wrote:
[SNIP]
Aehm. You got me here - I honestly don't know whether a friend
declaration is different from a "normal" declaration regarding this
;-) (damn, I *really* have to get a copy of the standard)


Ahh. I was hoping you will do the job. :-) I do not remember this
exactly either. I recall someone telling it does not pick up names
from other namespaces.


I mean from using directives. Using declarations were (IIRC) told to be
different.


Hm. further research turned up that it's considered a defect in the
standard, and there seemed to be some confusion how it should be handled:

http://anubis.dkuug.dk/jtc1/sc22/wg2...ctive.html#138

According to the website, an informal consensus has been reached -
although they don't mention which one???

kind regards
frank

--
Frank Schmitt
4SC AG phone: +49 89 700763-0
e-mail: frankNO DOT SPAMschmitt AT 4sc DOT com
Jul 19 '05 #9
Frank Schmitt wrote:
"Attila Feher" <at**********@lmf.ericsson.se> writes:
Attila Feher wrote:
Frank Schmitt wrote:
[SNIP]
Aehm. You got me here - I honestly don't know whether a friend
declaration is different from a "normal" declaration regarding this
;-) (damn, I *really* have to get a copy of the standard)

Ahh. I was hoping you will do the job. :-) I do not remember this
exactly either. I recall someone telling it does not pick up names
from other namespaces.


I mean from using directives. Using declarations were (IIRC) told
to be different.


Hm. further research turned up that it's considered a defect in the
standard, and there seemed to be some confusion how it should be
handled:

http://anubis.dkuug.dk/jtc1/sc22/wg2...ctive.html#138

According to the website, an informal consensus has been reached -
although they don't mention which one???


I could not see any consensus either. :-(

--
Attila aka WW
Jul 19 '05 #10
Frank Schmitt <in*****@seesignature.info> wrote in message news:<4c************@scxw21.4sc>...
"Attila Feher" <at**********@lmf.ericsson.se> writes:
Attila Feher wrote:
Frank Schmitt wrote:
[SNIP]
> Aehm. You got me here - I honestly don't know whether a friend
> declaration is different from a "normal" declaration regarding this
> ;-) (damn, I *really* have to get a copy of the standard)

Ahh. I was hoping you will do the job. :-) I do not remember this
exactly either. I recall someone telling it does not pick up names
from other namespaces.


I mean from using directives. Using declarations were (IIRC) told to be
different.


Hm. further research turned up that it's considered a defect in the
standard, and there seemed to be some confusion how it should be handled:

http://anubis.dkuug.dk/jtc1/sc22/wg2...ctive.html#138

According to the website, an informal consensus has been reached -
although they don't mention which one???


Perhaps they have yet to agree which consensus has been reached :)

GJD
Jul 19 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Daqian Yang | last post by:
hello all GCC gives me this error: g++ -c -o x-main_a2.o x-main_a2.cpp g++ -Wall -pedantic -c xfile_a2.cpp g++ -Wall -pedantic x-main_a2.o xfile_a2.o -o x Undefined ...
8
by: Petter Reinholdtsen | last post by:
I ran into a problem on HP-UX 11.00 the other day, where it refused to compile a program using 'using namespace std;' at the top. The reason seem to be that the compiler refuses to accept 'using...
5
by: Enos Meroka | last post by:
Hallo, I am a student doing my project in the university.. I have been trying to compile the program using HP -UX aCC compiler, however I keep on getting the following errors. ...
2
by: Tony Johansson | last post by:
Hello! I'm reading a book about C++ and there is something that I don't understand so I ask you. Below I have the text from the book and the code from the file where main is located and some...
3
by: Sandy | last post by:
Hi, I have two files as folllows file1.cpp #include<iostream> using namespace std; namespace { void show(); void fun() { cout<<"fun called\n"; } }
6
by: Steffen Hampel | last post by:
I got an rather large project which i recently startet to split up into namespaces. At a certain point the compiler (MSVC 6.0 sp5) began to give me C2871 errors ( 'name' : does not exist or is...
14
by: Jon Rea | last post by:
I am currently cleaning up an application which was origainlly hashed together with speed of coding in mind and therefore contains quite a few "hacky" shortcuts. As part of this "revamping"...
1
by: --== Alain ==-- | last post by:
Hi I've create a C++ managed Class as : *.h file -------- #pragma once #include "afxcmn.h" using namespace System::Design; using namespace System::Drawing::Design; using namespace...
0
by: richardbustarde | last post by:
I am new in .NET programming. I don't know if i miss out something on this. I have a main form (Form1) and a child form and another (MyLib.h) file that contains other supporting functions. They...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.