Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

E2015 Builder Error C++

Posted on 2011-03-10
15
Medium Priority
?
842 Views
Last Modified: 2012-06-22
I have two the following two functions defined by someone else in the same file.

inline std::string NumberFormatter::format(int value){//do something}
inline std::string NumberFormatter::format(unsigned value) {//do something}

While they compile OK in VS2010, it produces the following error in Borland C++ Builder XE.

[BCC32 Error] DynamicAnyHolder.h(910): E2015 Ambiguity between 'Poco::NumberFormatter::format(int) at E:\Projects\PocoFoundationBDS\include\Poco/NumberFormatter.h:384' and 'Poco::NumberFormatter::format(unsigned int) at E:\Projects\PocoFoundationBDS\include\Poco/NumberFormatter.h:426'

Why is that?
0
Comment
Question by:Mydeen Yussouf
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
  • 2
  • +1
15 Comments
 
LVL 53

Expert Comment

by:Infinity08
ID: 35099862
There shouldn't be an ambiguity, if you are calling the function with either an int or an unsigned int.

It would help if you showed the code that is actually causing this warning (and more specifically the type of the argument passed to the function).
0
 
LVL 12

Expert Comment

by:trinitrotoluene
ID: 35106182
>>>>BCC32 Error] DynamicAnyHolder.h(910):

what is there in line 910?

it is just not possible for this error to happen. That would mean Borland's compiler doesn't support overloading
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 35106432
>> it is just not possible for this error to happen.

It could be, depending on what type of argument is being passed to the function.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 35

Accepted Solution

by:
sarabande earned 336 total points
ID: 35107412
adding to last comment: if the type passed neither is int or unsigned int but could be converted to either of the two the compiler has an ambiguity. for example if you pass a long or a class type that has both conversions.

Sara
0
 
LVL 1

Author Comment

by:Mydeen Yussouf
ID: 35108852
THis function is being called with an argument of Int8 (a typedef for signed char). Despite the faact that this function is called in many places with the same argument only these two occurences I have poted earlier seem to cause the ambiguity. And this seem to happen only with Borland CPP Builder. As an added note I am trying to compile a C++ library developed in VS using CPP Builder 2010.
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 35108925
>> THis function is being called with an argument of Int8 (a typedef for signed char).

Could you post the exact code ?


If it is in fact a signed char that is causing the ambiguity error, then that seems to be a problem with the compiler. A signed char should cause the int version of the function to be called.
0
 
LVL 1

Author Comment

by:Mydeen Yussouf
ID: 35109098
@Infinity08,

This is the function that causes the error:

      void convert(std::string& val) const
      {
            val = NumberFormatter::format(_val); //causes error
      }

And this is how _val is defined:

private:
      Int8 _val;


While the typedef reads

      typedef signed char            Int8;
0
 
LVL 1

Author Comment

by:Mydeen Yussouf
ID: 35109152
Another instance where the same error occurs

[BCC32 Error] RegularExpression.cpp(308): E2015 Ambiguity between '
Poco::RegularExpression::match(const std::basic_string<char,std::char_traits<char>,std::allocator<char> > &,unsigned int,int) const at src\RegularExpression.cpp:160' and '
Poco::RegularExpression::match(const std::basic_string<char,std::char_traits<char>,std::allocator<char> > &,const std::basic_string<char,std::char_traits<char>,std::allocator<char> > &,int) at src\RegularExpression.cpp:303'

The line that's causing the error is:

 return re.match(subject,0, mtchOptions);

Seems like a difference in opinion between VS and Builder.

Appreciate deeper thoughts.
0
 
LVL 53

Assisted Solution

by:Infinity08
Infinity08 earned 664 total points
ID: 35109156
Ok, then the last line in my previous post applies.

You can of course explicitly cast it to an int to get around the error :

>>             val = NumberFormatter::format((int) _val); //causes error
0
 
LVL 53

Assisted Solution

by:Infinity08
Infinity08 earned 664 total points
ID: 35109545
>> Poco::RegularExpression::match(const std::basic_string<char,std::char_traits<char>,std::allocator<char> > &,unsigned int,int) const at src\RegularExpression.cpp:160' and '
>> Poco::RegularExpression::match(const std::basic_string<char,std::char_traits<char>,std::allocator<char> > &,const std::basic_string<char,std::char_traits<char>,std::allocator<char> > &,int) at src\RegularExpression.cpp:303'

That one is more understandable, but can be avoided by explicitly using an unsigned literal :

>>  return re.match(subject,0u, mtchOptions);

(assuming that subject is a std::string, and mtchOptions is an int).
0
 
LVL 1

Author Comment

by:Mydeen Yussouf
ID: 35109664
@Infinity08, while I agree the explicit type cast would solve the issues, I am trying to understand the behaviour better (ref my original post).

Actually a simple test as below works fine (correct me if its not close to what I have posted earlier:

typedef signed char Int8;

class CTest {

public:
      void f1(int value);
      void f1(unsigned value);

}; //class CTest

inline void f1(int value) {}
inline void f1(unsigned value) {}

int _tmain(int argc, _TCHAR* argv[])
{
      CTest c1;
      Int8 _val;
      c1.f1(_val);

      return 0;
}

But the compiler seems happy with this!
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 35109826
>> Actually a simple test as below works fine (correct me if its not close to what I have posted earlier:

You seem to have forgotten the CTest:: namespace qualifier for the function definitions.
A difference with the original case also seems to be that Poco::NumberFormatter::format is a static member function, and CTest::f1 is a non-static member function.


>> But the compiler seems happy with this!

If after the above modifications, the compiler still doesn't throw an error for the test code, then maybe different compiler flags/options have been used for both cases ?
Or maybe the code that causes the error, is otherwise causing the ambiguity, in a part that you haven't shown ?
Or maybe the compiler is inconsistent ?
0
 
LVL 35

Expert Comment

by:sarabande
ID: 35130620
can you post the statement at line 910 of  DynamicAnyHolder.h?

Sara
0
 
LVL 1

Author Comment

by:Mydeen Yussouf
ID: 35130942
@sarabande, here is the code:

      void convert(std::string& val) const
      {
910            val = NumberFormatter::format(_val);
      }


0
 
LVL 53

Expert Comment

by:Infinity08
ID: 35131236
olmuser, I wasn't aware that you still needed help with this. Could you let us know what it is that we can further help you with ?
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question