473,386 Members | 1,715 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,386 software developers and data experts.

ambiguity: same class declared twice

Hello world,
I seem to go from one tricky error to the other (at least tricky for
me). I am using qt and another code-package where many other files are
stored which I need (written by someone else). The problem is that
within this package and qt there are two definitions of the class
'Region' such that I get the compiler-error:

use of 'Region' is ambiguous
/usr/local/Trolltech/Qt-4.1.4/include/QtGui/qwindowdefs.h:124: error:
first declared as 'typedef struct _XRegion* Region' here
.../../robotcontrol/src/./ImageProcessing/ObjectAnalysis/ChainCoding.h:10:
error: also declared as 'class Tribots::Region' here

I tried explicitly selecting one of the "Regions" by providing a
namespace in front of them e.g. myNameSpace::Region but it did not
work, it still tells me it would be ambiguous... What can I do in such
a situation? Apparently both classes are not written by me and I do not
want to change any of both because it would destroy a lot of
dependencies in other classes...

Someone please help?

Thanks a lot in advance
T.K.

Aug 16 '06 #1
6 2176

"silversurfer2025" <ki****@web.dewrote in message
news:11*********************@h48g2000cwc.googlegro ups.com...
Hello world,
I seem to go from one tricky error to the other (at least tricky for
me). I am using qt and another code-package where many other files are
stored which I need (written by someone else). The problem is that
within this package and qt there are two definitions of the class
'Region' such that I get the compiler-error:

use of 'Region' is ambiguous
/usr/local/Trolltech/Qt-4.1.4/include/QtGui/qwindowdefs.h:124: error:
first declared as 'typedef struct _XRegion* Region' here
../../robotcontrol/src/./ImageProcessing/ObjectAnalysis/ChainCoding.h:10:
error: also declared as 'class Tribots::Region' here

I tried explicitly selecting one of the "Regions" by providing a
namespace in front of them e.g. myNameSpace::Region but it did not
work, it still tells me it would be ambiguous... What can I do in such
a situation? Apparently both classes are not written by me and I do not
want to change any of both because it would destroy a lot of
dependencies in other classes...
What's "Tribots"? A namespace? Which Region did you want? And what is it,
a type? A member?

I can't tell from that little information exactly what it is that you tried.

You need to show us the code that the error message is referring to. You
should always do this when asking about an error. (See the FAQ @
http://www.parashift.com/c++-faq-lite/ . especially section 5, for what's
expected when posting questions here.)

Namespaces are indeed the proper way to isolate identical symbols from each
other, but without more information, I can't tell where (or even if) they
can be used to fix your problem.

-Howard
Aug 16 '06 #2

Howard wrote:
"silversurfer2025" <ki****@web.dewrote in message
news:11*********************@h48g2000cwc.googlegro ups.com...
Hello world,
I seem to go from one tricky error to the other (at least tricky for
me). I am using qt and another code-package where many other files are
stored which I need (written by someone else). The problem is that
within this package and qt there are two definitions of the class
'Region' such that I get the compiler-error:

use of 'Region' is ambiguous
/usr/local/Trolltech/Qt-4.1.4/include/QtGui/qwindowdefs.h:124: error:
first declared as 'typedef struct _XRegion* Region' here
../../robotcontrol/src/./ImageProcessing/ObjectAnalysis/ChainCoding.h:10:
error: also declared as 'class Tribots::Region' here

I tried explicitly selecting one of the "Regions" by providing a
namespace in front of them e.g. myNameSpace::Region but it did not
work, it still tells me it would be ambiguous... What can I do in such
a situation? Apparently both classes are not written by me and I do not
want to change any of both because it would destroy a lot of
dependencies in other classes...

What's "Tribots"? A namespace? Which Region did you want? And what is it,
a type? A member?
The Tribots (namespace) Region is a class whereas the one in Qt is
'typedef struct _XRegion* Region' (simply a type-definition?)
>
I can't tell from that little information exactly what it is that you tried.
I am sorry, but what kind of code should I post? The source-Code from
Qt and the code from the other package?
>
You need to show us the code that the error message is referring to. You
should always do this when asking about an error. (See the FAQ @
http://www.parashift.com/c++-faq-lite/ . especially section 5, for what's
expected when posting questions here.)
I know the FAQ, but sometimes it is not that easy to find the right
code to post and I thought this was the right amount (even if it was
not compilable)..
>
Namespaces are indeed the proper way to isolate identical symbols from each
other, but without more information, I can't tell where (or even if) they
can be used to fix your problem.
Thanks anyway, I'll try to give more information...

OK Here we go:
-----------------------------------------------------
The Code from the Region.h:
#include <vector>
#include "../Formation/Image.h"
#include "../../Fundamental/Vec.h"
namespace Tribots {
class Region {
public:
int colClass;

inline Region(int colClass, int x, int y);
inline Region();

int getArea() const;
Vec getCenterOfGravity() const;
double getCompactness() const;

protected:
int area;
Vec centerOfGravity;
};
}
-----------------------------------------------------
ContourMeasure.h (where Region is used):
using namespace Tribots;

class ContourMeasure {
public:
static Tribots::Region* region;
};

PS: I know that there is a double use of Tribots in using namespace and
directly before the type.. This was just a try to beat the compiler
error, which apparently did not worl :(
-----------------------------------------------------
I skip the code from Qt here or should I post it as well? I guess the
line which is important is already in the error message:

/usr/local/Trolltech/Qt-4.1.4/include/QtGui/qregion.h:103: error: use
of 'Region' is ambiguous
/usr/local/Trolltech/Qt-4.1.4/include/QtGui/qwindowdefs.h:124: error:
first declared as 'typedef struct _XRegion* Region' here
.../../robotcontrol/src/./ImageProcessing/ObjectAnalysis/ChainCoding.h:10:
error: also declared as 'class Tribots::Region' here
--------------------------------------------------
Now what I do not understand is that the class ChainCoding (where the
class Region is defined) is part of another namespace as Qt, so why
does the compiler not like it? Furthermore, the error message refers to
files within Qt, so what can I do about that?

Thanks once more, hope this is enough code to make myself clear :P

Greetings and thanks a lot
Tim

PS I do not know how to put compilable code in here because this would
include Qt-Files and the other Package :(

Aug 17 '06 #3
silversurfer2025 schrieb:
ContourMeasure.h (where Region is used):
using namespace Tribots;
Don't ever write any
"using namespace XXXX" in a header file. It bites!
class ContourMeasure {
public:
static Tribots::Region* region;
};

-----------------------------------------------------
I skip the code from Qt here or should I post it as well? I guess the
line which is important is already in the error message:

/usr/local/Trolltech/Qt-4.1.4/include/QtGui/qregion.h:103: error: use
of 'Region' is ambiguous
/usr/local/Trolltech/Qt-4.1.4/include/QtGui/qwindowdefs.h:124: error:
first declared as 'typedef struct _XRegion* Region' here
../../robotcontrol/src/./ImageProcessing/ObjectAnalysis/ChainCoding.h:10:
error: also declared as 'class Tribots::Region' here
--------------------------------------------------
Well, try to include the qt stuff first.

If it doesn't help, show us the order of includes of the cpp file where
this error messages appears.

--
Thomas
Aug 17 '06 #4

Thomas J. Gritzan wrote:
silversurfer2025 schrieb:
ContourMeasure.h (where Region is used):
using namespace Tribots;

Don't ever write any
"using namespace XXXX" in a header file. It bites!
OK, I'll try. I just used this because in the original file there were
a lot of classes from the Tribots-namespace...
>
class ContourMeasure {
public:
static Tribots::Region* region;
};

-----------------------------------------------------
I skip the code from Qt here or should I post it as well? I guess the
line which is important is already in the error message:

/usr/local/Trolltech/Qt-4.1.4/include/QtGui/qregion.h:103: error: use
of 'Region' is ambiguous
/usr/local/Trolltech/Qt-4.1.4/include/QtGui/qwindowdefs.h:124: error:
first declared as 'typedef struct _XRegion* Region' here
../../robotcontrol/src/./ImageProcessing/ObjectAnalysis/ChainCoding.h:10:
error: also declared as 'class Tribots::Region' here
--------------------------------------------------

Well, try to include the qt stuff first.
Thank you Thomas, it worked,... wonderful! Still I do not get why
exactly... could you eventually explain?

Greetings
Tim
>
Aug 17 '06 #5
silversurfer2025 schrieb:
Thomas J. Gritzan wrote:
>Well, try to include the qt stuff first.
Thank you Thomas, it worked,... wonderful! Still I do not get why
exactly... could you eventually explain?
You had something like this:
----------
#include "ContourMeasure.h"
#include <qregion.h> // or another header which includes this
....
----------

The compiler sees this, expanded by the preprocessor:

-------------------------------
// in Region.h, included by ContourMeasure.h:
namespace Tribots
{
class Region {};
};

// in ContourMeasure.h, included by your cpp file:
using namespace Tribots;

// code lines in <qregion.h>
....
-------------------------------

The class definition defines Tribots::Region, the using directive puts the
name Region in the global scope.
In qregion.h another Region is declared by typedef, so you have two things
with equal name "Region" in your global scope.

When referenced in qregion.h, the compiler cannot decide which one two use.

Just remove the 'using namespace' from any header and put it - when needed
- in the cpp file _after any #include directives_, or better just use full
qualified names, or simple "using Tribots::Region" where you need it more
frequently.

You can also put the using-directives inside of a class definition or a
function body:

int main()
{
using std::cout;
using std::endl;

cout << "stuff" << endl;
}

--
Thomas
Aug 17 '06 #6

Thomas J. Gritzan wrote:
silversurfer2025 schrieb:
Thomas J. Gritzan wrote:
Well, try to include the qt stuff first.
Thank you Thomas, it worked,... wonderful! Still I do not get why
exactly... could you eventually explain?

You had something like this:
----------
#include "ContourMeasure.h"
#include <qregion.h> // or another header which includes this
...
----------

The compiler sees this, expanded by the preprocessor:

-------------------------------
// in Region.h, included by ContourMeasure.h:
namespace Tribots
{
class Region {};
};

// in ContourMeasure.h, included by your cpp file:
using namespace Tribots;

// code lines in <qregion.h>
...
-------------------------------

The class definition defines Tribots::Region, the using directive puts the
name Region in the global scope.
In qregion.h another Region is declared by typedef, so you have two things
with equal name "Region" in your global scope.

When referenced in qregion.h, the compiler cannot decide which one two use.

Just remove the 'using namespace' from any header and put it - when needed
- in the cpp file _after any #include directives_, or better just use full
qualified names, or simple "using Tribots::Region" where you need it more
frequently.

You can also put the using-directives inside of a class definition or a
function body:

int main()
{
using std::cout;
using std::endl;

cout << "stuff" << endl;
}

--
Thomas
Thanks a lot, now it is way clearer :)

Aug 17 '06 #7

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

Similar topics

5
by: Gianni Mariani | last post by:
Can anyone enligten me why I get the "ambiguous overload" error from the code below: friendop.cpp: In function `int main()': friendop.cpp:36: ambiguous overload for `std::basic_ostream<char,...
11
by: Kimmo Laine | last post by:
I'm flipping my wig here, people. I'm using classes and making each class a file. when I'm including dependet classess, I use require_once to avoid multiple declarations - yet they happen. I put...
3
by: hurcan solter | last post by:
Consider the code fragment; class A { public: A(){} A(int prm):mprm(prm){} int mprm; }; class B:public A {
3
by: subramanian100in | last post by:
I have tried the following in VC++ 2005 Express Edition and g++ in Linux. Consider the class class my_complex { public: my_complex(double r, double i = 10.0) : re(r), im(i) { }...
1
by: teejayem | last post by:
This is kind of hard for me to explain so I hope you understand. I have declared an object based on a class of a form I have designed. This is declared at Class level within the frmMain class of...
6
by: bogus1one | last post by:
Hi All Given the following: // NamespaceTemplate.cpp : Defines the entry point for the console application. // #include "stdafx.h"
3
by: Adam Nielsen | last post by:
Hi everyone, I've run into yet another quirk with templates, which IMHO is a somewhat limiting feature of the language. It seems that if you inherit multiple classes, and those classes have...
10
by: subramanian100in | last post by:
consider the following program: #include <iostream> using namespace std; class my_complex { public: friend ostream & operator<<(ostream &os, const my_complex &c);
4
by: abendstund | last post by:
Hi, I have the following code and trouble with ambiguity due to operator overloading.. The code is also at http://paste.nn-d.de/441 snip>>
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.