shared_ptr and Visual Studio 2008 Express SP1

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

shared_ptr and Visual Studio 2008 Express SP1

Sergey Sadovnikov
Hello All,

During migrating my project under new development environment I face
out following issue: ambiguous unqualified 'shared_ptr' name resolution.

For example in .cpp files I using several usings such as:

using namespace std;
using namespace std::tr1;
using namespace boost;

In source code I have something like this:

shared_ptr<SomeType> var = /*...*/;

And for each such line I have an error:
error C2872: 'shared_ptr' : ambiguous symbol
        could be 'c:\program files\microsoft visual studio 9.0\vc\include\memory(1392) : std::tr1::shared_ptr'
        or       'c:\program files\microsoft visual studio 9.0\vc\include\memory(1392) : std::tr1::shared_ptr'
        or       'p:\projects\common\boost_1.36.0\boost\shared_ptr.hpp(165) : boost::shared_ptr'

What I have to do to avoid this errors for boost 1.36 except explicit
share_ptr qualification?

Explicit including of "boost/shared_ptr" or "memory" I already put into
#ifdef/#endif braces. But this didn't help.
--
Best Regards,
 Sergey                          mailto:[hidden email]


_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: shared_ptr and Visual Studio 2008 Express SP1

Patrick Loney
>During migrating my project under new development environment I face
>out following issue: ambiguous unqualified 'shared_ptr' name
resolution.

>For example in .cpp files I using several usings such as:

>using namespace std;
>using namespace std::tr1;
>using namespace boost;

>In source code I have something like this:

>shared_ptr<SomeType> var = /*...*/;

>And for each such line I have an error:

>What I have to do to avoid this errors for boost 1.36 except explicit
>share_ptr qualification?

Personally I'd get rid of all the using statements and then you'd never
get this sort of error again. If you're too slow a typist to write
boost::shared_ptr when you need it then typedef it to something shorter.

Alternatively remove all #includes to boost\shared_ptr.hpp, or
\include\memory. You don't need to include both the MS and boost
shared_ptrs. Of course this won't work if some library header include
the header you remove in which case see above.

******************************************************************************

"This message and any attachments are solely for the intended recipient and may contain confidential and privileged information. If you are not the intended recipient, any disclosure, copying, use, or distribution of the information included in this message and any attachments is prohibited. If you have received this communication in error, please notify us by reply e-mail and immediately and permanently delete this message and any attachments. Thank you."

Interactive Transaction Solutions Ltd (2473364 England)

Registered Office:
Systems House,
Station Approach
Emsworth PO10 7PW

**********************************************************************

Ce message électronique contient des informations confidentielles à l'usage unique des destinataires indiqués, personnes physiques ou morales. Si vous n'êtes pas le destinataire voulu, toute divulgation, copie, ou diffusion ou toute autre utilisation de ces informations, est interdite. Si vous avez reçu ce message électronique par erreur, nous vous remercions d'en avertir son expéditeur immédiatement par email et de détruire ce message ainsi que les éléments attachés.

Interactive transaction Solutions SAS- France (RCS Pontoise : 489 397 877)

Siège social :
Parc Saint Christophe,
10, Avenue de l’Entreprise
95865 Cergy-Pontoise Cedex

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: shared_ptr and Visual Studio 2008 Express SP1

Igor R.
In reply to this post by Sergey Sadovnikov
Hi,

"using" the whole namespace is not healthy, because you "dirty" the
global namespace and raise the probability of conflicts. Instead, you
could "import" some specific classes:
using boost::shared_ptr;
Then, if you decide to use the tr1 one, you just change it to:
using std::tr1::shared_ptr;

>
> For example in .cpp files I using several usings such as:
>
> using namespace std;
> using namespace std::tr1;
> using namespace boost;
>
> In source code I have something like this:
>
> shared_ptr<SomeType> var = /*...*/;
>
> And for each such line I have an error:
> error C2872: 'shared_ptr' : ambiguous symbol
_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: shared_ptr and Visual Studio 2008 Express SP1

John Maddock
Igor R wrote:

>>> For example in .cpp files I using several usings such as:
>>>
>>> using namespace std;
>>> using namespace std::tr1;
>>> using namespace boost;
>>>
>>> In source code I have something like this:
>>>
>>> shared_ptr<SomeType> var = /*...*/;
>>>
>>> And for each such line I have an error:
>>> error C2872: 'shared_ptr' : ambiguous symbol

Nothing unusual about that: you have two different shared_ptr's visible in
scope: boost::shared_ptr and std::tr1::shared_ptr.  You need to decide which
you intend to use and either prefix all shared_ptr usages with the
appropriate qualifiers, or else just take care to only import the one
shared_ptr in the first place.

HTH, John.

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: shared_ptr and Visual Studio 2008 Express SP1

Sergey Sadovnikov
In reply to this post by Sergey Sadovnikov
Hello, John.

Wednesday, November 5, 2008 at 7:37:00 PM you wrote:

JM> Nothing unusual about that: you have two different shared_ptr's visible in
JM> scope: boost::shared_ptr and std::tr1::shared_ptr.  You need to decide which
JM> you intend to use and either prefix all shared_ptr usages with the
JM> appropriate qualifiers, or else just take care to only import the one
JM> shared_ptr in the first place.

I understand what I have two visible versions of shared_ptr. And in my
code I exclude all "boost/shared_ptr.hpp" inclusions. But what I have
to do with boost headers such as
"date_time/gregorian/greg_month.hpp" which also include shared_ptrs?
I understand, what 'using' is quite dangerous directive, but I use it
only in implementation files and never in headers. It makes source
code more shortly and readable. Just compare:

std::tr1::bind(&std::tr1::shared_ptr<SomeType>::get,
std::tr1::placeholders::_1, /* ... */);

with

bind(&shared_ptr<SomeType>::get, _1);

:) In the first case code semantic hidden under fully-qualified names.


--
Best Regards,
 Sergey                          mailto:[hidden email]


_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: shared_ptr and Visual Studio 2008 Express SP1

Ryan Gallagher-3
Sergey Sadovnikov <flex_ferrum <at> artberg.ru> writes:
[snip]
> I understand, what 'using' is quite dangerous directive, but I use it
> only in implementation files and never in headers. It makes source
> code more shortly and readable.

...and ambiguous.

[snip]

If you really don't want to qualify the names each place they're used then try
just adding "using std::tr1::shared_ptr;" after all these locations where you
already do "using namespace *".  If I recall correctly, the using declaration
will override the names from the using directives thus disambiguating it.

-Ryan



_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: shared_ptr and Visual Studio 2008 Express SP1

Roman Perepelitsa-3
2008/11/6 Ryan Gallagher <[hidden email]>
If you really don't want to qualify the names each place they're used then try
just adding "using std::tr1::shared_ptr;" after all these locations where you
already do "using namespace *".  If I recall correctly, the using declaration
will override the names from the using directives thus disambiguating it.

Unfortunately using declaration won't override using directive.

Roman Perepelitsa.

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: shared_ptr and Visual Studio 2008 Express SP1

Sergey Sadovnikov
In reply to this post by Ryan Gallagher-3
Hello, Ryan.

Thursday, November 6, 2008 at 6:26:24 AM you wrote:

RG> Sergey Sadovnikov <flex_ferrum <at> artberg.ru> writes:
RG> [snip]
>> I understand, what 'using' is quite dangerous directive, but I use it
>> only in implementation files and never in headers. It makes source
>> code more shortly and readable.

RG> ...and ambiguous.
In some rarely cases like this.

RG> [snip]

RG> If you really don't want to qualify the names each place they're used then try
RG> just adding "using std::tr1::shared_ptr;" after all these locations where you
RG> already do "using namespace *".  If I recall correctly, the using declaration
RG> will override the names from the using directives thus disambiguating it.
Unfortunately it doesn't help.

I think it would be good idea to avoid such ambiguous on the library level.
For example, in the boost/shared_ptr.hpp make following corrections:

//...
#ifdef _HAS_TR1
#include <memory>

namespace boost
{
   using std::tr1::shared_ptr;
   //... other usings
}
#else
// rest of the shared_ptr.hpp
#endif

Because of, for example, boost::shared_ptr_cast does not work with
std::tr1::shared_ptr. And I think there is not necessary to have two
different implementations of 'shared_ptr', 'bind', 'function' and other in
case when such implementation already shipped with compiler (such as
VS 2008 SP1 and gcc 4.3.x and newer).

--
Best Regards,
 Sergey                          mailto:[hidden email]


_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: shared_ptr and Visual Studio 2008 Express SP1

Ryan Gallagher-3
In reply to this post by Roman Perepelitsa-3
Roman Perepelitsa <roman.perepelitsa <at> gmail.com> writes:

>
>
> 2008/11/6 Ryan Gallagher <ryan.gallagher <at> gmail.com>
>> If you really don't want to qualify the names each place they're
>> used then try just adding "using std::tr1::shared_ptr;" after
>> all these locations where you already do "using namespace *".  
>> If I recall correctly, the using declaration will override the
>> names from the using directives thus disambiguating it.
>
>
> Unfortunately using declaration won't override using directive.

Actually, they do, but only when used at local scope.  (At least
according to MSVC 9.0 express.)  My post was still wrong, but moving
"using std::tr1::shared_ptr" to top of the offending functions would
resolve it.  Still not the approach I'd go with myself.

-Ryan

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users