Topic: Is typeof legal under ANSI C++?
Author: Michael R Cook <mcook@cognex.com>
Date: 1996/04/13 Raw View
"I\qaky P\irez Gonz\alez" <inaky@eneline.es> writes:
> So, my cuestion is that of the subject. Does typeof() conform to ANSI C++?
No, but you're in luck, because you don't really seem to need it:
> template<class T>
> class A
> {
> public:
typedef T type;
> virtual T& operator [] (unsigned int i) {return 3; };
> };
>
> template<class T>
> class B
> {
> public:
virtual T::type operator[] (unsigned int i)
> {
> return (*a)[i];
> };
That solution assumes you can modify the definition of `A'.
Michael.
[ 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 ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: "I\qaky P\irez Gonz\alez" <inaky@eneline.es>
Date: 1996/04/10 Raw View
Hi!!
I'm facing a BIG problem, developing under GCC/2.7.2 and the only
sollution I've found is using the "typeof()" keyword, but I'm afraid of
losing compatibility and those things ...
So, my cuestion is that of the subject. Does typeof() conform to
ANSI C++?
The problem is the following: I have a templated class, named A,
which may be applied the array operator. Then I have another templated
class, name it B which is an smart pointer to classes of any type (in
fact, this is used for classes which have a resource count which
has to be kept updated ... more or less like the Fresco toolkit and a
lot more I don't know of :).
Well, the idea is that when "working daily" with objects of class
A, they'll be pointers, and when storing the pointers into smart pointers,
you have to dereference it and then apply the operator array, like
(*b)[4], which is kind of ugly. This is not too important, but when you
are refering to nested arrays of smart pointers, it keeps going uglier
(for example (*(*(*b)[3])[1])[4] for a three-level nested array).
So, if I manage to make a method in the smart pointer which passes
the array operator to the item it points to and returns a reference to the
object it returns, I am done. Here is where the typeof() keyword appears.
If not, I don't know which type to return in the array operator of the
smart pointer.
Here is the simplified code explaining the example ...
template<class T>
class A
{
public:
virtual T& operator [] (unsigned int i) {return 3; };
};
template<class T>
class B
{
public:
virtual typeof((*a)[0]) operator[] (unsigned int a)
{
return (*a)[i];
};
virtual operator T* () const
{
return a;
}
T* a;
};
int main (void)
{
A<int> df;
B<A<int> > tf;
return tf[2];
}
Well, this is all folks :) TIA
--Inaky Perez Gonzalez <inaky@peloncho.fis.ucm.es> <2:341/5.31@fidonet.org> --
--- PGP Key fingerprint = 8E 34 3A 62 64 99 E2 44 AD 7B 30 D9 DD FF 3E 4C ---
(PGP public key available via finger/e-mail request)
[ 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 ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]