* RE: using keyword problem
@ 2004-08-27 12:27 L.Suresh
0 siblings, 0 replies; 3+ messages in thread
From: L.Suresh @ 2004-08-27 12:27 UTC (permalink / raw)
To: gcc-help; +Cc: artur
The using-declaration is used to bring every declaration with a given
name into scope. Here when you say A::S, there is no namespace "A", it
is the name of the class.
Try the code below.
class A
{
public:
struct S
{
int x;
};
};
int Method()
{
A::S s;
s.x = 1;
return s.x;
};
Thanks,
L.Suresh
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: using keyword problem
2004-08-27 12:18 Artur Szostak
@ 2004-08-27 15:03 ` Eljay Love-Jensen
0 siblings, 0 replies; 3+ messages in thread
From: Eljay Love-Jensen @ 2004-08-27 15:03 UTC (permalink / raw)
To: artur, gcc-help
Hi Artur,
The "using" keyword is for bring identifiers from one namespace available
in the current namespace.
For example:
using std::cout; // cout is now accessible, without the std:: qualifier.
using namespace std: // the whole std:: uberverse is accessible. Avoid
collisions!
A class and a struct or sort of like namespaces, and also not like namespaces.
You want to do this...
class A
{
public:
struct S
{
int x;
};
};
int Method()
{
typedef A::S S; // using A::S is no good here.
S s;
s.x = 1;
return s.x;
};
HTH,
--Eljay
^ permalink raw reply [flat|nested] 3+ messages in thread
* using keyword problem
@ 2004-08-27 12:18 Artur Szostak
2004-08-27 15:03 ` Eljay Love-Jensen
0 siblings, 1 reply; 3+ messages in thread
From: Artur Szostak @ 2004-08-27 12:18 UTC (permalink / raw)
To: gcc-help
Why does the following code not compile under GCC?
Is this not valid C++?
class A
{
public:
struct S
{
int x;
};
};
int Method()
{
using A::S;
S s;
s.x = 1;
return s.x;
};
When compiling the above code as is from source file main.cxx the following
output is generated:
$ g++ main.cxx -o test
main.cxx: In function `int Method()':
main.cxx:12: parse error before `::' token
main.cxx:14: `S' undeclared (first use this function)
main.cxx:14: (Each undeclared identifier is reported only once for each
function it appears in.)
main.cxx:15: `s' undeclared (first use this function)
$
--
Artur Szostak
Physics Department
University of Cape Town
Rondebosch
7701
South Africa
Work: +27 21 650 3356
Mobile: +27 82 297 9502
Email: artur@alice.phy.uct.ac.za or artursz@iafrica.com
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2004-08-27 12:18 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-27 12:27 using keyword problem L.Suresh
-- strict thread matches above, loose matches on Subject: below --
2004-08-27 12:18 Artur Szostak
2004-08-27 15:03 ` Eljay Love-Jensen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).