-5

I'm trying to convert a code in C to C++ language and I get an error but I've no idea what's the source of the problem.

here is the source code: http://pastebin.com/PnKvgNsR

The error message is:

call of overloaded ‘dateTimeToMinutes(char*&)’ is ambiguous

Compiling with g++4.7.1 (included c++11 standard).

Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084
MiP
  • 5
  • 3

2 Answers2

2

In your cpp file specify the namespace RabQavSystem in your definitions of dateTimeXXX functions.

int RabQavSystem::dateTimeDifference(DateTime datetime1, DateTime datetime2) 
{
    ...
}

int RabQavSystem::dateTimeToMinutes(DateTime datetime)
{
    ...
}
home_monkey
  • 79
  • 1
  • 5
  • Thanks man ! I thought I tried to be more specific but it really worked for me.. – MiP Sep 25 '12 at 13:25
2

In your header, you declare two functions in the RabQavSystem namespace:

namespace RabQavSystem {
    int dateTimeToMinutes(DateTime datetime);
    int dateTimeDifference(DateTime datetime1, DateTime datetime2);
}

In your source file, you declare and define new functions in the global namespace; these are not definitions of the functions declared in the header, but of different functions in a different namespace:

int dateTimeDifference(DateTime datetime1, DateTime datetime2) {
    // ....
}

int dateTimeToMinutes(DateTime datetime) {
    // ....
}

Then using namespace RabQavSystem; pulls the other function names into the global namespace, causing the ambiguity.

To fix it, you want to define the functions in your namespace, not the global namespace:

int RabQavSystem::dateTimeDifference(DateTime datetime1, DateTime datetime2) {
    ^^^^^^^^^^^^^^
}

int RabQavSystem::dateTimeToMinutes(DateTime datetime) {
    ^^^^^^^^^^^^^^
}
Mike Seymour
  • 249,747
  • 28
  • 448
  • 644