-2

I am currently programming a NMEA Parser in C++, and have been given a few pre-declared functions. I'm testing each function as I go along, but I've hit a snag in programming the decomposeSentence function. The code for the function is as follows:

NMEAPair decomposeSentence(const string & nmeaSentence) {
    /* Extract each comma-separated value from the string, and place into an
     * array. */
    string newSentence = nmeaSentence;
    vector<string> sep = split(newSentence, ',');

    /* Extract the sentence type (e.g. GPGLL) from the vector, remove the "$",
     * and remove from the vector. */
    string sentenceType = sep[0];
    sentenceType.erase(sentenceType.begin());
    sep.erase(sep.begin());

    /* Extract the part of the vector containing the checksum, and discard the
     * checksum. Remove the part of the vector still containing the checksum,
     * and replace this with the newly created value. */
    string discardChecksum = sep.back();
    discardChecksum = discardChecksum.substr(0, discardChecksum.find("*"));
    sep.erase(sep.end());
    sep.push_back(discardChecksum);

    /* Combine the sentence type and the vector elements into a pair. */
    NMEAPair decomposedSentence = make_pair(sentenceType, sep);

    /* Return the decomposed sentence. */
    return decomposedSentence;
}

When I try running the function in main(), like so...

int main() {
    const string nmeaSentence = "$GPGGA,091138.000,5320.4819,N,00136.3714,W,1,0,,395.0,M,,M,,*46";
    NMEAPair decomposedSentence = decomposeSentence(nmeaSentence);
}

... the compiler throws the error call of overloaded 'decomposeSentence(const string&)' is ambiguous'.

I realise this is probably a very simple issue to troubleshoot, but I would appreciate it if anyone could help me solve it.

Edit: full error message

../gps/src/main.cpp:52:65: error: call of overloaded ‘decomposeSentence(const string&)’ is ambiguous
     NMEAPair decomposedSentence = decomposeSentence(nmeaSentence);
                                                                 ^
../gps/src/main.cpp:23:10: note: candidate: GPS::NMEAPair decomposeSentence(const string&)
 NMEAPair decomposeSentence(const string & nmeaSentence) {
          ^~~~~~~~~~~~~~~~~
In file included from ../gps/src/main.cpp:1:0:
../gps/headers/parseNMEA.h:47:12: note: candidate: GPS::NMEAPair GPS::decomposeSentence(const string&)
   NMEAPair decomposeSentence(const string & nmeaSentence);
            ^~~~~~~~~~~~~~~~~
make: *** [Makefile:721: main.o] Error 1
04:00:01: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project GPS (kit: Desktop)
Rob Dudley
  • 25
  • 8

1 Answers1

0

It sounds like you have using namespace GPS; somewhere in your code. Because of that, GPS::decomposeSentence and the global decomposeSentence are being picked by the compiler as potential overloads.

You can resolve the problem by:

  1. Removing the using namespace GPS; line, or
  2. Putting the global function in another namespace and using it explicitly from that namespace.

namespace ThisFileNS
{
   NMEAPair decomposeSentence(const string & nmeaSentence) 
   {
      ...
   }
}

and use

NMEAPair decomposedSentence = ThisFileNS::decomposeSentence(nmeaSentence);

in main.

R Sahu
  • 204,454
  • 14
  • 159
  • 270