MESSAGE
DATE | 2016-11-09 |
FROM | Ruben Safir
|
SUBJECT | Subject: [Hangout-NYLXS] namespace and external files confusion
|
[This mail was also posted to comp.lang.c++.]
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?
--
So many immigrant groups have swept through our town
that Brooklyn, like Atlantis, reaches mythological
proportions in the mind of the world - RI Safir 1998
http://www.mrbrklyn.com
DRM is THEFT - We are the STAKEHOLDERS - RI Safir 2002
http://www.nylxs.com - Leadership Development in Free Software
http://www2.mrbrklyn.com/resources - Unpublished Archive
http://www.coinhangout.com - coins!
http://www.brooklyn-living.com
Being so tracked is for FARM ANIMALS and and extermination camps,
but incompatible with living as a free human being. -RI Safir 2013
_______________________________________________
hangout mailing list
hangout-at-nylxs.com
http://www.nylxs.com/
|
|