Topic: Virtual on block code
Author: "Samee Zahur" <samee.zahur@gmail.com>
Date: Mon, 25 Apr 2005 10:19:13 CST Raw View
I'd like everone's opinion on this:
Every now and then we write up classes with *nothing* but abstract
functions - interfaces, as they are called. When writing up about a
dozen function prototypes, the need to prefix 'virtual' and suffix '=0'
can often get annoying for the coder as well as for the reader. So
can't we have a shortcut syntax like:
virtual
{ void fun1(int,int);
int blah(float);
}=0;
What does everyone else here think?
Samee
---
[ 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://www.jamesd.demon.co.uk/csc/faq.html ]
Author: v.Abazarov@comAcast.net (Victor Bazarov)
Date: Mon, 25 Apr 2005 15:58:59 GMT Raw View
Samee Zahur wrote:
> I'd like everone's opinion on this:
> Every now and then we write up classes with *nothing* but abstract
> functions - interfaces, as they are called. When writing up about a
> dozen function prototypes, the need to prefix 'virtual' and suffix '=0'
> can often get annoying for the coder as well as for the reader. So
> can't we have a shortcut syntax like:
>
> virtual
> { void fun1(int,int);
> int blah(float);
> }=0;
>
> What does everyone else here think?
I think it makes the class definition harder to read than
virtual void fun1(int,int) = 0;
virtual int blah(float) = 0;
However, I can see defining a whole class as 'interface' by use of
'virtual' in the class definition:
class virtual ABC {
public:
void fun1(int,int);
int blah(float);
};
which should mean that all functions are virtual and pure (including
the compiler-provided destructor and the assignment op). The d-tor
should be trivial in that case IIUIC and its purity is superficial.
Not sure it can be done or whether it already has been suggested.
V
---
[ 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://www.jamesd.demon.co.uk/csc/faq.html ]