Sunday, May 31, 2015

Digest for comp.lang.c++@googlegroups.com - 3 updates in 1 topic

Christian Gollwitzer <auriocus@gmx.de>: May 31 08:37AM +0200

Am 31.05.15 um 00:46 schrieb Stefan Ram:
 
> int main()
> { int std = 3;
> std::cout << std << '\n'; }
 
I can't find a problem here. In C++, namespaces and variables live in a
different domain. This would be different in Python, where a module is
actually an object and can be passed around and assigned to. But in C++
there is no way to do such a thing, as in the fictional code below.
 
namespace mystd=::std;
void doitthere(namespace where) {
where::cout<<"Something";
}
 
doitthere(mystd);
 
 
 
 
Christian
Marcel Mueller <news.5.maazl@spamgourmet.org>: May 31 09:11AM +0200

On 31.05.15 00.46, Stefan Ram wrote:
 
> int main()
> { int std = 3;
> std::cout << std << '\n'; }
 
::std::cout << std
 
fixes the name clash.
 
 
Marcel
"Öö Tiib" <ootiib@hot.ee>: May 31 05:14AM -0700

On Sunday, 31 May 2015 10:11:34 UTC+3, Marcel Mueller wrote:
> > std::cout << std << '\n'; }
 
> ::std::cout << std
 
> fixes the name clash.
 
There are none to fix. That int std can not be considered as
class-name-or-namespace-name so it does not participate as one in
construction of qualified-id 'std::cout'.
 
In general such code is useful as a test case for a parser of C++
or as element of obfuscation.
It would be lot easier for everybody if the compiler said that the name
'std' is taken already and suggested to use some other for that int.
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.

No comments: