Topic: deriving from void?
Author: "Claude Quizel" <Claude_Quezel@Syntell.corba>
Date: 1999/12/08 Raw View
return void has been added to the language to help build templates. Has
deriving from void being discused?
template<class T>
class Test : public T {
// ...
}
Test<void> test; // same as no public T
--
Claude Qu=E9zel (claude_quezel@syntell.corba)
anti-spam: replace corba by com in private replies
---
[ 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 ]
Author: Gabriel Dos_Reis <gdosreis@korrigan.inria.fr>
Date: 1999/12/08 Raw View
"Claude Quizel" <Claude_Quezel@Syntell.corba> writes:
| return void has been added to the language to help build templates. Has
| deriving from void being discused?
More generally you can't derive from a fundamental type.
But yes, void is special : it is an incomplete type :-)
What wuold you gain from deriving from an incomplete type?
--
Gabriel Dos Reis, dosreis@cmla.ens-cachan.fr
[ 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 ]
Author: Darin Adler <darin@bentspoon.com>
Date: 1999/12/08 Raw View
Claude Quizel <Claude_Quezel@Syntell.corba> wrote:
> return void has been added to the language to help build templates. Has
> deriving from void being discused?
>
> template<class T>
> class Test : public T {
> // ...
> }
>
> Test<void> test; // same as no public T
Without commenting on the usefulness of this idiom, I'll point out that if
you want this, you can make it work with the traits technique. The names in
this example are a bit ill-considered, but it does demonstrate how you would
use the technique:
class empty_class { };
template<typename T> struct inherit_void_traits
{ typedef T type; };
template<> struct inherit_void_traits<void>
{ typedef empty_class type; };
template<typename T>
class Test : public inherit_void_traits<T>
{
};
Test<void> test; // inherits from empty_class
This approach would not have worked for "return void", so I think it's good
that a change was made to the language for that case.
-- Darin
[ 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 ]