Topic: Defineof pure virtual func in class definiton ?
Author: Steve Clamage <stephen.clamage@eng.sun.com>
Date: 1997/07/01 Raw View
Jim Hyslop wrote:
>
> In article <33AE2BAC.1A9B@vf.vodafone.co.uk> on 23 Jun 1997 13:45:04
> PDT, paul.black@vf.vodafone.co.uk says...
> > "(C) Chichiang Wan" <wanc@hpclear6.cup.hp.com> wrote:
> > > Why is that disallowed ? Can someone tell me the reason ?
> >
> > The simplest answer must be that any combination of inline
> > functions and the pure specifier would look silly.
> Gee, thanks, Paul. I never realized how important not being silly was
> to Stroustrup.
>
> Now that we're done kidding around, I'd like to see a *serious* answer
> to the question - why *can't* you define a pure virtual function in
> the class declaration?
Although "silly" is not a particularly good way to describe
the situtation, I think the answer was substantially correct.
When pure virtual functions were added to C++, every effort
was being made to avoid adding new keywords to the language.
Otherwise, some other notation, perhaps
class X {
pure virtual int f();
might have been adopted. (The alert reader will have noticed
that avoiding new keywords seems no longer to be a priority. :-)
Given the "=0" syntax for pure virtual functions, it seemed
inappropriate to combine that with defining the function
inside the class. That is,
virtual int f() = 0 { blah blah blah blah }
looks strange and is hard to read. It also seems a reasonable
assumption that pure virtual functions will be provided with
bodies infrequently, so losing the ability to define the
body in the class seems unimportant.
--
Steve Clamage, stephen.clamage@eng.sun.com
---
[ 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: "(C) Chichiang Wan" <wanc@hpclear6.cup.hp.com>
Date: 1997/07/02 Raw View
Steve Clamage wrote:
>
>
> Given the "=0" syntax for pure virtual functions, it seemed
> inappropriate to combine that with defining the function
> inside the class. That is,
> virtual int f() = 0 { blah blah blah blah }
> looks strange and is hard to read. It also seems a reasonable
> assumption that pure virtual functions will be provided with
> bodies infrequently, so losing the ability to define the
> body in the class seems unimportant.
>
You would not let the language be less expressive without good reason.
Reason like people are unlikely to use it does not sound very
persuasive.
As the syntax difficulties. What exactly are they ? What syntax looks
more intelligent or aesthetic is one thing. But isn't it a little
surprising that such subjective thing can be so much so that it is the
only reason.
Might there be an implication that we have to pay extra syntax (grammer)
to allow inside class definition ? not simply you pay extra semantic
effort to disallow it ?
member-declarator:
declarator pure-specifieropt
--
**********************************************************************
Name: Chichiang Wan
email: wanc@cup.hp.com
Phone: (408) 447-5762
**********************************************************************
---
[ 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: Paul Black <paul.black@vf.vodafone.co.uk>
Date: 1997/06/23 Raw View
"(C) Chichiang Wan" <wanc@hpclear6.cup.hp.com> wrote:
> Why is that disallowed ? Can someone tell me the reason ?
The simplest answer must be that any combination of inline
functions and the pure specifier would look silly.
Paul
paul.black@vf.vodafone.co.uk
(The from address will be fixed when VF support sort
their collective lives out).
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]
Author: "(C) Chichiang Wan" <wanc@hpclear6.cup.hp.com>
Date: 1997/06/27 Raw View
Paul Black wrote:
>
> "(C) Chichiang Wan" <wanc@hpclear6.cup.hp.com> wrote:
> > Why is that disallowed ? Can someone tell me the reason ?
>
> The simplest answer must be that any combination of inline
> functions and the pure specifier would look silly.
>
You answer is simple, indeed. Unfortunately, without your further
elaboration, I could only guess what you meant might be: 1) function
defined inside class is inline function and they have to be inlined, no
matter how you call it. 2) because pure-specified is taken the place of
function body, how can you have another {} ? 3) pure means not only you
have to provide definiton when you derive, it also means you can't
provide {} inside class. And...
--
**********************************************************************
Name: Chichiang Wan
email: wanc@cup.hp.com
Phone: (408) 447-5762
**********************************************************************
---
[ 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: Paul Black <paul.black@vf.vodafone.co.uk>
Date: 1997/06/27 Raw View
"(C) Chichiang Wan" <wanc@hpclear6.cup.hp.com> wrote:
> Paul Black wrote:
> >
> > "(C) Chichiang Wan" <wanc@hpclear6.cup.hp.com> wrote:
> > > Why is that disallowed ? Can someone tell me the reason ?
> >
> > The simplest answer must be that any combination of inline
> > functions and the pure specifier would look silly.
> >
> You answer is simple, indeed. Unfortunately, without your further
> elaboration, I could only guess what you meant might be: 1) function
> defined inside class is inline function and they have to be inlined, no
> matter how you call it. 2) because pure-specified is taken the place of
> function body, how can you have another {} ? 3) pure means not only you
> have to provide definiton when you derive, it also means you can't
> provide {} inside class. And...
I was actually thinking more of the general clumsiness of the syntax
(I can only guess the reason as to why it's not allowed).
Defining a function declared as pure virtual is unusual (I've been
using C++ for 5 years and only found out about 6 months ago that it
was permissable). Defining such a function inline is rarer still.
Since there is another way to define member functions as inline
(whether they are pure virtual or not), it must have been easier to
disallow the definition of a pure virtual inline function in a class
definition than to fudge the syntax.
Consider some possible syntax:
virtual void func() = {}
virtual void func() {} = 0;
virtual void func() = 0 {}
Let's face it, they do look a bit silly!
It wouldn't have been so bad if a new keyword was added:
pure virtual void func() {}
or
pure_virtual void func() {}
Still we just have to live with:
class Foo
{
virtual void func() = 0;
};
inline void Foo::func() {}
Paul
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]
Author: jim.hyslop@leitch.com (Jim Hyslop)
Date: 1997/06/28 Raw View
In article <33AE2BAC.1A9B@vf.vodafone.co.uk> on 23 Jun 1997 13:45:04
PDT, paul.black@vf.vodafone.co.uk says...
> "(C) Chichiang Wan" <wanc@hpclear6.cup.hp.com> wrote:
> > Why is that disallowed ? Can someone tell me the reason ?
>
> The simplest answer must be that any combination of inline
> functions and the pure specifier would look silly.
Gee, thanks, Paul. I never realized how important not being silly was
to Stroustrup.
Now that we're done kidding around, I'd like to see a *serious* answer
to the question - why *can't* you define a pure virtual function in
the class declaration?
--
Jim Hyslop
There are two kinds of people in this world: those who think there are
two kinds of people, and those who don't.
Don't pass on that email about someone dying of cancer or a "new
super-powerful computer virus" until you check out the Internet Hoax
page http://ciac.llnl.gov/ciac/CIACHoaxes.html first!
---
[ 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: "(C) Chichiang Wan" <wanc@hpclear6.cup.hp.com>
Date: 1997/06/20 Raw View
Why is that disallowed ? Can someone tell me the reason ?
--
**********************************************************************
Name: Chichiang Wan
email: wanc@cup.hp.com
Phone: (408) 447-5762
**********************************************************************
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]