Topic: Unnamed Classes and typeof() keyword
Author: rado42@my-dejanews.com
Date: 1998/11/18 Raw View
In article <72sh6f$fi8$1@newsmonger.rutgers.edu>,
"Ajay Wanchoo" <wanchoo@caip.rutgers.edu> wrote:
>
> Hi,
> Pl. consider the following (also pl. note that I'm not an expert):
>
> 1. One can't specify member functions and more importantly any ctor/dtor
> for unnamed classes. It *might* be useful to have a mechanism to allow
> this (especially for small/trivial classes that have only one instance in
> the
> entire program).
> e.g.
> class{
> int a;
> char *b;
> }Alpha;// I might want to initialize the integer a, and allot some memory to
> b
>
> 2. Maybe an identifier like "this" (pointer to self object) i.e. a ref to
> the class
> like a "thisclass" identifier would help to resolve which class is being
> referred to. It may even help in regular coding, even though you could get
> the class info using the typeid operator.
>
> 3. Further, even inheritance is not allowed, which is sad but that's another
> story.
>
> Ajay
>
My advice is: just use name for your class. If you want to hide this name,
use anonimous namespace:
namespace // anonimous
{
class MyClass
{
whatever members
}
whatever_vars;
} // end of namespace.
MyClass will be only visible in its particular file. Bad if it were in a
header...
But: it brings me to yet another usage of the proposed in other mails keyword
'typeof' (which is supposed to give the type of its argument):
class /*unnamed*/
{
public:
typeof (*this) // Constructor?
{}
~typeof (*this) // Destructor?
{}
// etc.
} xx;
class MyClass : public typeof (xx)
{}
Radoslav Getov
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
---
[ 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 ]