Topic: using declaration" for symbols defined in a class
Author: "Alberto Barbati" <albbarbZZZ@tin.it>
Date: 1998/02/09 Raw View
Hi,
You all know what this piece of code mean:
namespace mynamespace
{
int somevariable;
};
using mynamespace::somevariable;
The following piece of code is illegal, but, according to me,
may be of some use:
class myclass
{
...
public:
static int somevariable;
};
using myclass::somevariable;
The same syntax may be appied to typedefs, enums, and static member
functions. In many cases, this use of the using declaration is just
to make names short, but look at the following code:
class myclass
{
...
private:
static int somevariable;
public:
static int getsomevariable() { return somevariable; }
};
using myclass::getsomevariable;
you get that myclass has full access to somevariable, while the rest
of the world has read-only access to it via a non-qualified inline =
function
(without the class-using directive you get either non-qualified or =
inline).
Any comments are appreciated.
Alberto Barbati
--
Please remove ZZZ from my e-ddress when replying
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]