MESSAGE
DATE | 2016-11-09 |
FROM | Ruben Safir
|
SUBJECT | Re: [Learn] namespace and external files confusion
|
From learn-bounces-at-nylxs.com Wed Nov 9 11:11:45 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 8B33E161312; Wed, 9 Nov 2016 11:11:45 -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 4898A160E77 for ; Wed, 9 Nov 2016 11:11:43 -0500 (EST) To: learn-at-nylxs.com References: <877f8cocz1.fsf-at-contrapunctus.net> From: Ruben Safir Message-ID: Date: Wed, 9 Nov 2016 11:11:43 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <877f8cocz1.fsf-at-contrapunctus.net> Subject: Re: [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="windows-1252" Content-Transfer-Encoding: quoted-printable Errors-To: learn-bounces-at-nylxs.com Sender: "Learn"
On 11/09/2016 11:05 AM, Christopher League wrote: > =
> In the .cpp file, it's not enough to say `using namespace merge`. You > also want to be *defining* things in that same namespace. Otherwise you > are defining `::track` but trying to recursively call `merge::track`. > =
> Change that `using namespace merge` into `namespace merge { ....... }` > that covers the rest of the definitions. > =
> That compiles. > =
I did that finally, just three minutes ago. I didn't know why. There are so many words in these books on this topic and nothing is clear.
I'm gonna write an FAQ on this if I have time. Meanwhile I have now 5 hours to parralize this and debug it ...
> CL > =
> Ruben Safir writes: > =
>> [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 =91track(int*&, int&, int&, int*&)=92 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 =91track(int*&, int&, int&, int*&)=92 is ambiguous >> >> gvim sees it right away as well >> >> >> || gcc -M *.cpp >make.deps >> || g++ -Wall -ggdb -c msort.cpp >> || msort.cpp: In function =91void track(int*, int, int, int*)=92: >> msort.cpp|25 col 29| error: call of overloaded =91track(int*&, int&, int= &, >> int*&)=92 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 > =
> =
> =
> _______________________________________________ > Learn mailing list > Learn-at-nylxs.com > http://lists.mrbrklyn.com/mailman/listinfo/learn > =
-- =
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
|
|