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

ambiguous definition


compile error:

test1.cpp:21: error: ISO C++ says that
`T mtd::CDiffOperator::getdp(const mtd::mVector&, long int,
mtd::mBCTYPE) const'
and
`void mtd::CDiffOperator::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 3944

xuatla 写道:
compile error:

test1.cpp:21: error: ISO C++ says that
`T mtd::CDiffOperator::getdp(const mtd::mVector&, long int,
mtd::mBCTYPE) const'
and
`void mtd::CDiffOperator::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::CDiffOperator::getdp(const mtd::mVector&, long int,
mtd::mBCTYPE) const'
and
`void mtd::CDiffOperator::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.com> wrote:

compile error:

test1.cpp:21: error: ISO C++ says that
`T mtd::CDiffOperator::getdp(const mtd::mVector&, long int,
mtd::mBCTYPE) const'
and
`void mtd::CDiffOperator::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
Sep 27 '05 #4
Dave Rahardja wrote:
On Mon, 26 Sep 2005 19:20:35 -0700, xuatla <xu****@gmail.com> wrote:

compile error:

test1.cpp:21: error: ISO C++ says that
`T mtd::CDiffOperator::getdp(const mtd::mVector&, long int,
mtd::mBCTYPE) const'
and
`void mtd::CDiffOperator::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 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.com> wrote:

compile error:

test1.cpp:21: error: ISO C++ says that
`T mtd::CDiffOperator::getdp(const mtd::mVector&, long int,
mtd::mBCTYPE) const'
and
`void mtd::CDiffOperator::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
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
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....
9
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...
1
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...
6
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...
4
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()':...
3
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...
2
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...
32
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;...
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...
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...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.