Popping mad
unread,Nov 9, 2016, 10:37:24 AM11/9/16You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to han...@nylxs.com, le...@nylxs.com
I'm doing this simple merge sort program and I'm tripping on this error
C++ call of overloaded ‘track(int*&, int&, int&, int*&)’ is ambiguous
I think this comes down to my confusion with namespace and I'm not finding a good reference with C++
on namespace usage in different files
I have merge.h
#ifndef MSORT_INC
#define MSORT_INC
namespace merge{
int max(int x, int y);
void track(int* , int , int , int* );
int sort(int &input , int size);
}
#endif /* ----- #ifndef MSORT_INC ----- */
and merge.cpp
#include "msort.h"
using namespace merge;
int max(int x, int y){
int ret;
x>y ? ret=x : ret=y;
return ret;
}
void track(int* in, int left, int right, int* space)
{
int i = 0;
int length = right - left;
if(right == left + 1){
return;
}
int mpt = length/2;
int pos1 = left;
int pos2 = left + mpt;
int pos3 = right;
//do the recursion now on the left and right branches
track(in, pos1, pos2, space);
track(in, pos2, pos3, space);
for(i = 0; i < length; i++)
{
if(pos1 < pos2 && ( pos2 == pos3 || max(in[pos1], in[pos2]) == in[pos1]))
{
space[i] = in[pos1];
pos1++;
}
else{
space[i] = in[pos2];
pos2++;
}
}
/* transfer array segment */
for(i = left; i < right; i++)
{
in[i] = space[i - left];
}
}
And the error I get is
C++ call of overloaded ‘track(int*&, int&, int&, int*&)’ is ambiguous
gvim sees it right away as well
|| gcc -M *.cpp >make.deps
|| g++ -Wall -ggdb -c msort.cpp
|| msort.cpp: In function ‘void track(int*, int, int, int*)’:
msort.cpp|25 col 29| error: call of overloaded ‘track(int*&, int&, int&, int*&)’ is ambiguous
|| track(in, pos1, pos2, space);
|| ^
msort.cpp|11 col 6| note: candidate: void track(int*, int, int, int*)
|| void track(int* in, int left, int right, int* space)
|| ^~~~~
msort.h|25 col 6| note: candidate: void merge::track(int*, int, int, int*)
|| void track(int* , int , int , int* );
|| ^~~~~
and it seems to identify the definition in the .cpp file as a separate declaration than the declation in the .h file
What am I doing wrong?