 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Otto Lind Guest
|
Posted: Fri Mar 05, 2004 7:43 pm Post subject: static_cast and globally scoped types. |
|
|
The following program shows the problem:
#include <stdio.h>
namespace x
{
enum L { One = 1, Two = 2 };
namespace x
{
enum L { Three = 3, Four = 4 };
void foo(long mylong)
{
: ::L l;
//
// This fails to compile due to syntax error
//
l = static_cast<: ::L>(mylong);
//
// This (correctly) fails to compile since it uses
// wrong enum.
//
l = static_cast<x::L>(mylong);
}
}
}
int main()
{
long l = 1;
x: ::foo(l);
return 0;
}
When compiled with g++ (3.3.2) and Sun's CC (5.5 Patch 113817-03), both
report a syntax error when using a globally scoped type:
% CC foo.cpp
"foo.cpp", line 19: Error: "<" expected instead of "<:".
"foo.cpp", line 19: Error: Type name expected instead of "<:".
"foo.cpp", line 19: Error: Expected an expression.
"foo.cpp", line 24: Error: Cannot assign x: ::L to x::L.
% g++ foo.cpp
foo.cpp: In function `void x: ::foo(long int)':
foo.cpp:19: error: parse error before `[' token
foo.cpp:24: error: cannot convert `x: ::L' to `x::L' in assignment
I had assumed that globally scoped types could be used in static_cast<>,
specifically to resolve scope issues. Is this a bug in the compiler? If
not, what would be the best workaround?
Otto
--
Otto Lind Kabira Technologies (http://www.kabira.com)
[email]otto (AT) olcs (DOT) com[/email] 12193 285th street, Lindstrom, MN 55045
|
|
| Back to top |
|
 |
Leor Zolman Guest
|
Posted: Fri Mar 05, 2004 8:08 pm Post subject: Re: static_cast and globally scoped types. |
|
|
On 05 Mar 2004 19:43:14 GMT, [email]otto (AT) olcs (DOT) com[/email] (Otto Lind) wrote:
| Quote: | The following program shows the problem:
#include <stdio.h
namespace x
{
enum L { One = 1, Two = 2 };
namespace x
{
enum L { Three = 3, Four = 4 };
void foo(long mylong)
{
: ::L l;
//
// This fails to compile due to syntax error
//
l = static_cast<: ::L>(mylong);
|
Looks like <: is a diagraph equivalent of '[', believe it or not (I didn't
know that...). Put a space after the <.
| Quote: | //
// This (correctly) fails to compile since it uses
// wrong enum.
//
l = static_cast
right. |
-leor
Leor Zolman
BD Software
[email]leor (AT) bdsoft (DOT) com[/email]
www.bdsoft.com -- On-Site Training in C/C++, Java, Perl & Unix
C++ users: Download BD Software's free STL Error Message
Decryptor at www.bdsoft.com/tools/stlfilt.html
|
|
| Back to top |
|
 |
Sam Dennis Guest
|
Posted: Fri Mar 05, 2004 8:14 pm Post subject: Re: static_cast and globally scoped types. |
|
|
Otto Lind wrote:
| Quote: | l = static_cast<: ::L>(mylong);
When compiled with g++ (3.3.2) and Sun's CC (5.5 Patch 113817-03), both
report a syntax error when using a globally scoped type:
"foo.cpp", line 19: Error: "<" expected instead of "<:".
|
Your problem is not the same as the problem you think it is; `<:' is the
digraph for `[' (in C, at least, and I would think that this is the same
in C++), so you do, indeed, have a syntax error.
Try this, instead:
l = static_cast< : ::L >(mylong);
--
++acr@,ka"
|
|
| Back to top |
|
 |
Leor Zolman Guest
|
Posted: Fri Mar 05, 2004 8:15 pm Post subject: Re: static_cast and globally scoped types. |
|
|
On Fri, 05 Mar 2004 20:08:02 GMT, Leor Zolman <leor (AT) bdsoft (DOT) com> wrote:
| Quote: | Looks like <: is a diagraph equivalent of '[', believe it or not (I didn't
know that...). Put a space after the <.
And yes, I /do/ know how to spell "digraph". That was Freudian slip of the |
fingers.
-leor
Leor Zolman
BD Software
[email]leor (AT) bdsoft (DOT) com[/email]
www.bdsoft.com -- On-Site Training in C/C++, Java, Perl & Unix
C++ users: Download BD Software's free STL Error Message
Decryptor at www.bdsoft.com/tools/stlfilt.html
|
|
| Back to top |
|
 |
jacob navia Guest
|
Posted: Sat Mar 06, 2004 9:28 am Post subject: Re: static_cast and globally scoped types. |
|
|
"Sam Dennis" <sam (AT) malfunction (DOT) screaming.net> a écrit dans le message de
news:slrnc4hnsj.teh.sam (AT) ID-227112 (DOT) user.uni-berlin.de...
| Quote: | Otto Lind wrote:
l = static_cast<: ::L>(mylong);
When compiled with g++ (3.3.2) and Sun's CC (5.5 Patch 113817-03), both
report a syntax error when using a globally scoped type:
"foo.cpp", line 19: Error: "<" expected instead of "<:".
Your problem is not the same as the problem you think it is; `<:' is the
digraph for `[' (in C, at least, and I would think that this is the same
in C++), so you do, indeed, have a syntax error.
Try this, instead:
l = static_cast< : ::L >(mylong);
--
|
I have proposed in comp.std.c that WE FORGET this digraph/trigraph
nonsense...
I can't understand that C++ needs to be bug compatible with C.
How many "incredible" bugs we will endure?
In C this is less of a problem than in C++, where <: is much more common!
jacob
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|