473,883 Members | 1,709 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ambiguous definition


compile error:

test1.cpp:21: error: ISO C++ says that
`T mtd::CDiffOpera tor::getdp(cons t mtd::mVector&, long int,
mtd::mBCTYPE) const'
and
`void mtd::CDiffOpera tor::getdp(mtd: :mVector&, const mtd::mVector&,
mtd::mBCTYPE) const'
are ambiguous even though the worst conversion for the former is better
than the worst conversion for the latter

'mtd::mVector' is a class. Why the compile thinks these two functions
are ambigous?

Thanks in advance for the help.

X
Sep 27 '05 #1
9 3981

xuatla 写道:
compile error:

test1.cpp:21: error: ISO C++ says that
`T mtd::CDiffOpera tor::getdp(cons t mtd::mVector&, long int,
mtd::mBCTYPE) const'
and
`void mtd::CDiffOpera tor::getdp(mtd: :mVector&, const mtd::mVector&,
mtd::mBCTYPE) const'
are ambiguous even though the worst conversion for the former is better
than the worst conversion for the latter

'mtd::mVector' is a class. Why the compile thinks these two functions
are ambigous?

Thanks in advance for the help.

X


it's because the second parament,if you set an int number and it can't
chose to use which fuction

Sep 27 '05 #2

xuatla wrote:
compile error:

test1.cpp:21: error: ISO C++ says that
`T mtd::CDiffOpera tor::getdp(cons t mtd::mVector&, long int,
mtd::mBCTYPE) const'
and
`void mtd::CDiffOpera tor::getdp(mtd: :mVector&, const mtd::mVector&,
mtd::mBCTYPE) const'
are ambiguous even though the worst conversion for the former is better
than the worst conversion for the latter

'mtd::mVector' is a class. Why the compile thinks these two functions
are ambigous?

Thanks in advance for the help.

X


Some more detail, including the actual declarations would probably be
of help here. But one way that a member name can be ambiguous in a
derived class, is for that name to appear separately in two base
classes and neither of those two base classes inherit from the other.
Note that it is the "name" that is ambiguous and that causes the error
in this case The error occurs before the compiler attempts to resolve
an overloaded function call. The actual declarations of the functions
whose names are ambiguous are not a factor and have no bearing on the
ambiguity.

An explicit qualification for the name will resolve the ambiguity by
indicating which class or namespace the name can be found.

Greg

Sep 27 '05 #3
On Mon, 26 Sep 2005 19:20:35 -0700, xuatla <xu****@gmail.c om> wrote:

compile error:

test1.cpp:21 : error: ISO C++ says that
`T mtd::CDiffOpera tor::getdp(cons t mtd::mVector&, long int,
mtd::mBCTYPE ) const'
and
`void mtd::CDiffOpera tor::getdp(mtd: :mVector&, const mtd::mVector&,
mtd::mBCTYPE ) const'
are ambiguous even though the worst conversion for the former is better
than the worst conversion for the latter

'mtd::mVecto r' is a class. Why the compile thinks these two functions
are ambigous?

Thanks in advance for the help.

X


What are the types of the parameters that you are passing to getdp? It may be
that mtd::mVector has a constructor taking a long, and you're trying to pass
parameters of types ([non-const]mtd::mVector, long, mtd::mBCTYPE), and the
compiler can't decide whether to convert the first parameter to a const
mtd::mVector&, or to construct a temporary mtd::mVector, passing a long as a
parameter.

-dr
Sep 27 '05 #4
Dave Rahardja wrote:
On Mon, 26 Sep 2005 19:20:35 -0700, xuatla <xu****@gmail.c om> wrote:

compile error:

test1.cpp:2 1: error: ISO C++ says that
`T mtd::CDiffOpera tor::getdp(cons t mtd::mVector&, long int,
mtd::mBCTYP E) const'
and
`void mtd::CDiffOpera tor::getdp(mtd: :mVector&, const mtd::mVector&,
mtd::mBCTYP E) const'
are ambiguous even though the worst conversion for the former is better
than the worst conversion for the latter

'mtd::mVector ' is a class. Why the compile thinks these two functions
are ambigous?

Thanks in advance for the help.

X

What are the types of the parameters that you are passing to getdp? It may be
that mtd::mVector has a constructor taking a long, and you're trying to pass
parameters of types ([non-const]mtd::mVector, long, mtd::mBCTYPE), and the
compiler can't decide whether to convert the first parameter to a const
mtd::mVector&, or to construct a temporary mtd::mVector, passing a long as a
parameter.

-dr


Thanks for all the help.
class mVector
{
private:
int size;
double *ele;
public:
mVector(long int size=1);
mVector(const mVector&);
};

And there's no type change between mVector and long int or int.

To call, I use
mtd::mVector vec;
mtd::mBCTYPE bc;
getdp(vec, 1, bc);

The 2nd argument is a (long)int here.

dr - in your reply, do you mean that the compiler may use the 2nd
argument as a parameter of mtd::mVector's constructor and then cause the
ambiguous problem? I just can't understand why it can automatically
'construct' an object.

Also, the above problem occured in my test. I used mtd::mVector as a
template class. everything is fine. And then after I undefine the
template part and make it a non-template class, the above problem happened.

Thank all again for the help.

X
Sep 27 '05 #5
On Tue, 27 Sep 2005 10:24:34 -0700, xuatla wrote:
<snip>
To call, I use
mtd::mVector vec;
mtd::mBCTYPE bc;
getdp(vec, 1, bc);

The 2nd argument is a (long)int here.


Not to the compiler.

1 is an int.
1L is a long int.

- Jay
Sep 27 '05 #6

my question again:
I wrote a simple code to test the ambigous definition problem:
--------------

#include <iostream>

class A
{
public:
double e;
A(double d=1.0) { e = d; } ;
} ;

class B
{
public:
void func(const A& a1, int i) const // func (1)
{ std::cout << 1 << std::endl; } ;

void func(const A& a1, const A& a2) const // func (2)
{ std::cout << 2 << std::endl; } ;
} ;

int main()
{
A a1, a2;
B b;

b.func(a1, 1); // test (I)
b.func(a1, a2); // test (II)

return 1;
}

---------------

no problem for above code.

But:

if I change func (2) to:
void func(A& a1, const A& a2) const // func (2)
{ std::cout << 2 << std::endl; } ;
i.e., remove the 'const' from the first argument, then compile error
occured for test (I):

testc.cpp:24: error: ISO C++ says that `void B::func(const A&, int)
const' and `void B::func(A&, const A&) const' are ambiguous even though
the worst conversion for the former is better than the worst conversion
for the latter.

No compile error for test (II) (I commented out test (I) and tried (II)
only, passed).

----------------

If I also removed 'const' from func (1), then compile ok.

Anyone knows the reason? Thank you.

X
xuatla wrote:
Dave Rahardja wrote:
On Mon, 26 Sep 2005 19:20:35 -0700, xuatla <xu****@gmail.c om> wrote:

compile error:

test1.cpp:21: error: ISO C++ says that
`T mtd::CDiffOpera tor::getdp(cons t mtd::mVector&, long int,
mtd::mBCTYPE) const'
and
`void mtd::CDiffOpera tor::getdp(mtd: :mVector&, const mtd::mVector&,
mtd::mBCTYPE) const'
are ambiguous even though the worst conversion for the former is
better than the worst conversion for the latter

'mtd::mVector' is a class. Why the compile thinks these two functions
are ambigous?

Thanks in advance for the help.

X


What are the types of the parameters that you are passing to getdp? It
may be
that mtd::mVector has a constructor taking a long, and you're trying
to pass
parameters of types ([non-const]mtd::mVector, long, mtd::mBCTYPE), and
the
compiler can't decide whether to convert the first parameter to a const
mtd::mVector&, or to construct a temporary mtd::mVector, passing a
long as a
parameter.

-dr

Thanks for all the help.
class mVector
{
private:
int size;
double *ele;
public:
mVector(long int size=1);
mVector(const mVector&);
};

And there's no type change between mVector and long int or int.

To call, I use
mtd::mVector vec;
mtd::mBCTYPE bc;
getdp(vec, 1, bc);

The 2nd argument is a (long)int here.

dr - in your reply, do you mean that the compiler may use the 2nd
argument as a parameter of mtd::mVector's constructor and then cause the
ambiguous problem? I just can't understand why it can automatically
'construct' an object.

Also, the above problem occured in my test. I used mtd::mVector as a
template class. everything is fine. And then after I undefine the
template part and make it a non-template class, the above problem happened.

Thank all again for the help.

X

Sep 28 '05 #7
xuatla wrote:

my question again:
I wrote a simple code to test the ambigous definition problem:
--------------

#include <iostream>

class A
{
public:
double e;
A(double d=1.0) { e = d; } ;
} ;

class B
{
public:
void func(const A& a1, int i) const // func (1)
{ std::cout << 1 << std::endl; } ;

void func(const A& a1, const A& a2) const // func (2)
{ std::cout << 2 << std::endl; } ;
} ;

int main()
{
A a1, a2;
B b;

b.func(a1, 1); // test (I)
b.func(a1, a2); // test (II)

return 1;
}

---------------

no problem for above code.

But:

if I change func (2) to:
void func(A& a1, const A& a2) const // func (2)
{ std::cout << 2 << std::endl; } ;
i.e., remove the 'const' from the first argument, then compile error
occured for test (I):

testc.cpp:24: error: ISO C++ says that `void B::func(const A&, int)
const' and `void B::func(A&, const A&) const' are ambiguous even though
the worst conversion for the former is better than the worst conversion
for the latter.

No compile error for test (II) (I commented out test (I) and tried (II)
only, passed).

----------------

If I also removed 'const' from func (1), then compile ok.

Anyone knows the reason? Thank you.

X


Well this stuff is complex and intricate but here goes.

Given

void func(const A& a1, int i) const // func (1)
{ std::cout << 1 << std::endl; } ;

void func(A& a1, const A& a2) const // func (2)
{ std::cout << 2 << std::endl; } ;

and

func(a1, 1); // test (I)

func (2) is preferred on the first argument and func (1) is prefered on
the second argument. Hence it is ambiguous.

But given
void func(A& a1, int i) const // func (1)
{ std::cout << 1 << std::endl; } ;

void func(const A& a1, const A& a2) const // func (2)
{ std::cout << 2 << std::endl; } ;

func(a1, 1); // test (I)

func (1) is preferred on both arguments. Hence it is unambiguous.

john
Sep 28 '05 #8
John Harrison wrote:
xuatla wrote:

my question again:
I wrote a simple code to test the ambigous definition problem:
--------------

#include <iostream>

class A
{
public:
double e;
A(double d=1.0) { e = d; } ;
} ;

class B
{
public:
void func(const A& a1, int i) const // func (1)
{ std::cout << 1 << std::endl; } ;

void func(const A& a1, const A& a2) const // func (2)
{ std::cout << 2 << std::endl; } ;
} ;

int main()
{
A a1, a2;
B b;

b.func(a1, 1); // test (I)
b.func(a1, a2); // test (II)

return 1;
}

---------------

no problem for above code.

But:

if I change func (2) to:
void func(A& a1, const A& a2) const // func (2)
{ std::cout << 2 << std::endl; } ;
i.e., remove the 'const' from the first argument, then compile error
occured for test (I):

testc.cpp:24: error: ISO C++ says that `void B::func(const A&, int)
const' and `void B::func(A&, const A&) const' are ambiguous even
though the worst conversion for the former is better than the worst
conversion for the latter.

No compile error for test (II) (I commented out test (I) and tried
(II) only, passed).

----------------

If I also removed 'const' from func (1), then compile ok.

Anyone knows the reason? Thank you.

X

Well this stuff is complex and intricate but here goes.

Given

void func(const A& a1, int i) const // func (1)
{ std::cout << 1 << std::endl; } ;

void func(A& a1, const A& a2) const // func (2)
{ std::cout << 2 << std::endl; } ;

and

func(a1, 1); // test (I)

func (2) is preferred on the first argument and func (1) is prefered on
the second argument. Hence it is ambiguous.

Thank you!
If I change func (2) to
void func(A& a1, std::string c) const;
Then it's fine.
It seems that 'class object' & 'int' or 'double' etc can't be
disctincted well enough by compiler. But 'int' & 'string' can be.

I will change my code and give up 'const' for func (1) - I doubt it's
not a good manner. Thanks for all the replies and help.

-X

But given
void func(A& a1, int i) const // func (1)
{ std::cout << 1 << std::endl; } ;

void func(const A& a1, const A& a2) const // func (2)
{ std::cout << 2 << std::endl; } ;

func(a1, 1); // test (I)

func (1) is preferred on both arguments. Hence it is unambiguous.

john

Sep 29 '05 #9
xuatla wrote:
John Harrison wrote:
xuatla wrote:

my question again:
I wrote a simple code to test the ambigous definition problem:
--------------

#include <iostream>

class A
{
public:
double e;
A(double d=1.0) { e = d; } ;
} ;

class B
{
public:
void func(const A& a1, int i) const // func (1)
{ std::cout << 1 << std::endl; } ;

void func(const A& a1, const A& a2) const // func (2)
{ std::cout << 2 << std::endl; } ;
} ;

int main()
{
A a1, a2;
B b;

b.func(a1, 1); // test (I)
b.func(a1, a2); // test (II)

return 1;
}

---------------

no problem for above code.

But:

if I change func (2) to:
void func(A& a1, const A& a2) const // func (2)
{ std::cout << 2 << std::endl; } ;
i.e., remove the 'const' from the first argument, then compile error
occured for test (I):

testc.cpp:24: error: ISO C++ says that `void B::func(const A&, int)
const' and `void B::func(A&, const A&) const' are ambiguous even
though the worst conversion for the former is better than the worst
conversion for the latter.

No compile error for test (II) (I commented out test (I) and tried
(II) only, passed).

----------------

If I also removed 'const' from func (1), then compile ok.

Anyone knows the reason? Thank you.

X

Well this stuff is complex and intricate but here goes.

Given

void func(const A& a1, int i) const // func (1)
{ std::cout << 1 << std::endl; } ;

void func(A& a1, const A& a2) const // func (2)
{ std::cout << 2 << std::endl; } ;

and

func(a1, 1); // test (I)

func (2) is preferred on the first argument and func (1) is prefered
on the second argument. Hence it is ambiguous.


Thank you!
If I change func (2) to
void func(A& a1, std::string c) const;
Then it's fine.
It seems that 'class object' & 'int' or 'double' etc can't be
disctincted well enough by compiler. But 'int' & 'string' can be.


Well there is no conversion from int to string so there is no ambiguity
if you have

void func(const A& a1, int i) const; // func (1)
void func(A& a1, std::string c) const; // func(2)

func(a1, 1); // test (I)

It must call func (1).

I will change my code and give up 'const' for func (1) - I doubt it's
not a good manner. Thanks for all the replies and help.


Seems reasonable.

john
Sep 29 '05 #10

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

Similar topics

10
6151
by: Jason Heyes | last post by:
I have a class with two constructors that both take the same type of argument as a parameter. What should I do to disambiguate my class?
5
7849
by: Dave | last post by:
I trying to setup a time. The following code is in a function, Timer stateTimer = new Timer(ab(), null, 1000, 1000); I have included using System.Threading; at the begining of my code. When I try to compile I receive the error,
9
13288
by: Prasad | last post by:
HI, I am a beginner in VC++.. I am trying to write a Win32 console application in visual studio.. I am using following header files.. #include <STRING> using namespace std; #include <hash_map>//from Standard template library //and some other headers
1
1331
by: --== Alain ==-- | last post by:
Hi, Under VC++.net, if i include windows.h, and compile my application, i have several data types ambiguous, like IDataObject, IMessageFilter, IDropTarget,... so it means that they are defined in windows.h but also in some other namespaces. how can i do to still have my windows.h included and avoiding ambiguous
6
4166
by: Caleb | last post by:
I have a class that has two member functions of the same name: class MyClass { public: void someFunction(int arg); void someFunction(int arg, char blah); }; I'm trying to get a tr1::functional to the first one, for example:
4
2259
by: Chameleon | last post by:
Can anyone explain me why the code below produce (with mingw-g++) the following error message: --------------------------------------------------------------- main10.cpp: In function `int main()': main10.cpp:23: error: request for member `getZero' is ambiguous main10.cpp:12: error: candidates are: virtual int B::getZero(int) main10.cpp:6: error: virtual int A::getZero()...
3
1636
by: Tim H | last post by:
I understand why this is ambiguous, technically, but it seems, frankly, retarded to consider 0 as ambiguous but 1 as not, just because 0 == NULL. Is there any way to defeat this that does not involve changing all code that uses 0 as an argument to use bignum(0)? #include <string> using namespace std;
2
3921
by: =?Utf-8?B?TWluaS1Ub29scyBUaW1t?= | last post by:
I have an odd web services problem. I have a shared assembly (shared.dll) that is referenced both by a C# WinForms client (client.exe) and a C# Web Service (service.dll). When I upload the web service, naturally both service.dll and shared.dll are uploaded to the bin folder. In service.dll is defined a class called DataService that provides the web service methods I need. To access this web service, client.exe uses code in...
32
2128
by: Anna Smidt | last post by:
I am having an "ambiguous call to overloaded function" error again. This is the function: int nGetProfWidth (int ncols, unsigned ProfSpec) { if ((ProfSpec & PROF_2d) == 0) return ncols; return int(sqrt(ncols)); //HERE THE ERROR IS THROWN }
0
9940
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
11141
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10742
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7971
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7126
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5797
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4611
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4220
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3232
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.