MESSAGE
DATE | 2016-11-09 |
FROM | Ruben Safir
|
SUBJECT | Subject: [Learn] namespace and external files confusion
|
From learn-bounces-at-nylxs.com Wed Nov 9 10:37:29 2016 Return-Path: X-Original-To: archive-at-mrbrklyn.com Delivered-To: archive-at-mrbrklyn.com Received: from www.mrbrklyn.com (www.mrbrklyn.com [96.57.23.82]) by mrbrklyn.com (Postfix) with ESMTP id CF495161316; Wed, 9 Nov 2016 10:37:28 -0500 (EST) X-Original-To: learn-at-nylxs.com Delivered-To: learn-at-nylxs.com Received: from [10.0.0.62] (flatbush.mrbrklyn.com [10.0.0.62]) by mrbrklyn.com (Postfix) with ESMTP id 60DE4160E77; Wed, 9 Nov 2016 10:37:22 -0500 (EST) To: hangout-at-nylxs.com, learn-at-nylxs.com From: Ruben Safir Message-ID: Date: Wed, 9 Nov 2016 10:37:22 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 Subject: [Learn] namespace and external files confusion X-BeenThere: learn-at-nylxs.com X-Mailman-Version: 2.1.17 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: learn-bounces-at-nylxs.com Sender: "Learn"
[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 =E2=80=98track(int*&, int&, int&, int*&)=E2=80=99 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=3Dx : ret=3Dy; return ret; }
void track(int* in, int left, int right, int* space) { int i =3D 0; int length =3D right - left; =
if(right =3D=3D left + 1){ return; } int mpt =3D length/2; int pos1 =3D left; int pos2 =3D left + mpt; int pos3 =3D right; //do the recursion now on the left and right branches track(in, pos1, pos2, space); track(in, pos2, pos3, space); for(i =3D 0; i < length; i++) { if(pos1 < pos2 && ( pos2 =3D=3D pos3 || max(in[pos1], in[pos2]) =3D=3D in[pos1])) { space[i] =3D in[pos1]; pos1++; } else{ space[i] =3D in[pos2]; pos2++; } } /* transfer array segment */ for(i =3D left; i < right; i++) { in[i] =3D space[i - left]; } }
And the error I get is C++ call of overloaded =E2=80=98track(int*&, int&, int&, int*&)=E2=80=99 is= ambiguous
gvim sees it right away as well
|| gcc -M *.cpp >make.deps || g++ -Wall -ggdb -c msort.cpp || msort.cpp: In function =E2=80=98void track(int*, int, int, int*)=E2=80= =99: msort.cpp|25 col 29| error: call of overloaded =E2=80=98track(int*&, int&, = int&, int*&)=E2=80=99 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 _______________________________________________ Learn mailing list Learn-at-nylxs.com http://lists.mrbrklyn.com/mailman/listinfo/learn
|
|