Topic: Keyword abstract for pure virtual functions in c++0x


Author: Francis Glassborow <francis.glassborow@btinternet.com>
Date: Wed, 14 Oct 2009 12:37:32 CST
Raw View
Sean Hunt wrote:

    On Oct 11, 5:04 pm, PsiX <bglo...@googlemail.com> wrote:

        Thanks for the info!

        As for the why... why "x->" if there is "(*x)." why "!=" if there is !
        ( == )... why abstract if there is =0?
        (being the difference in the meaning that the compiler does not create
        a function body vs. the intention of what the programmer wants to say)
        because it helps the reading and understanding of code. And you could
        later say
        abstract class X{};


      [[abstract]] and [[concrete]] might be useful attributes for checking,
    but they wouldn't have any other use, as the abstractness of a class
    can be determined from its contents (note that an abstract class with
    no pure virtual members can very easily be done by making the
    destructor pure virtual; the destructor must be defined in derived
    classes so they don't notice that the parent is abstract).

Of course they notice because of the way that dtors chain together
which is why you have to define your dtor even if you have declared it
a pure virtual.

--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: Sean Hunt <rideau3@gmail.com>
Date: Thu, 15 Oct 2009 22:15:08 CST
Raw View
On Oct 14, 12:37 pm, Francis Glassborow
<francis.glassbo...@btinternet.com> wrote:
> Of course they notice because of the way that dtors chain together
> which is why you have to define your dtor even if you have declared it
> a pure virtual.

Yes, but because the compiler defines a destructor for you if you
don't provide one, all classes inheriting from it will always provide
a replacement definition, so the pureness of a destructor won't affect
any inheritors.

Sean Hunt


--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: Francis Glassborow <francis.glassborow@btinternet.com>
Date: Fri, 16 Oct 2009 09:31:06 CST
Raw View
Sean Hunt wrote:
> On Oct 14, 12:37 pm, Francis Glassborow
> <francis.glassbo...@btinternet.com> wrote:
>> Of course they notice because of the way that dtors chain together
>> which is why you have to define your dtor even if you have declared it
>> a pure virtual.
>
> Yes, but because the compiler defines a destructor for you if you
> don't provide one, all classes inheriting from it will always provide
> a replacement definition, so the pureness of a destructor won't affect
> any inheritors.
>
> Sean Hunt
>
>
No, the compiler only provides one if you have not declared it. As soon
as you write:

virtual ~mytype() = 0;

you have declared it and the compiler is not at liberty to generate one
for you (even though it would make some sense to allow that. Declaring
any function as a pure virtual simply requires that the function is to
be defined in derived classes it does not prevent definition within the
base class.

--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: PsiX <bgloger@googlemail.com>
Date: Fri, 9 Oct 2009 10:07:44 CST
Raw View
Are there any activities in the c++0x standardization to add
"abstract" as a keyword to specify pure virtual functions or classes?


--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: tohava <tohava@gmail.com>
Date: Fri, 9 Oct 2009 16:51:58 CST
Raw View
On Oct 9, 6:07 pm, PsiX <bglo...@googlemail.com> wrote:
> Are there any activities in the c++0x standardization to add
> "abstract" as a keyword to specify pure virtual functions or classes?

While I do not know much about C++0x standardization, I do know that
they're trying to avoid adding new keywords for the purpose of
backwards compatibility. Some baltant examples of this are the "=
delete" and "= default" suffixes for functions.


--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: Pavel Minaev <int19h@gmail.com>
Date: Sat, 10 Oct 2009 12:24:11 CST
Raw View
On Oct 9, 9:07 am, PsiX <bglo...@googlemail.com> wrote:
> Are there any activities in the c++0x standardization to add
> "abstract" as a keyword to specify pure virtual functions or classes?

It's not in the current draft, and I am not aware of any active
proposals on this. Which isn't surprising, as we already have "=0" for
this purpose, so why introduce a new keyword to cover a feature that
is already there?


--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: PsiX <bgloger@googlemail.com>
Date: Sun, 11 Oct 2009 17:04:42 CST
Raw View
On 10 Oct, 11:24, Pavel Minaev <int...@gmail.com> wrote:
> On Oct 9, 9:07 am, PsiX <bglo...@googlemail.com> wrote:
>
> > Are there any activities in the c++0x standardization to add
> > "abstract" as a keyword to specify pure virtual functions or classes?
>
> It's not in the current draft, and I am not aware of any active
> proposals on this. Which isn't surprising, as we already have "=0" for
> this purpose, so why introduce a new keyword to cover a feature that
> is already there?
>
> --
> [ comp.std.c++ is moderated.  To submit articles, try just posting with ]
> [ your news-reader.  If that fails, use mailto:std-...@netlab.cs.rpi.edu]
> [              --- Please see the FAQ before posting. ---               ]
> [ FAQ:http://www.comeaucomputing.com/csc/faq.html                     ]

Thanks for the info!

As for the why... why "x->" if there is "(*x)." why "!=" if there is !
( == )... why abstract if there is =0?
(being the difference in the meaning that the compiler does not create
a function body vs. the intention of what the programmer wants to say)
because it helps the reading and understanding of code. And you could
later say
abstract class X{};


--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: Sean Hunt <rideau3@gmail.com>
Date: Tue, 13 Oct 2009 11:54:48 CST
Raw View
On Oct 11, 5:04 pm, PsiX <bglo...@googlemail.com> wrote:
> Thanks for the info!
>
> As for the why... why "x->" if there is "(*x)." why "!=" if there is !
> ( == )... why abstract if there is =0?
> (being the difference in the meaning that the compiler does not create
> a function body vs. the intention of what the programmer wants to say)
> because it helps the reading and understanding of code. And you could
> later say
> abstract class X{};

[[abstract]] and [[concrete]] might be useful attributes for checking,
but they wouldn't have any other use, as the abstractness of a class
can be determined from its contents (note that an abstract class with
no pure virtual members can very easily be done by making the
destructor pure virtual; the destructor must be defined in derived
classes so they don't notice that the parent is abstract).

Sean Hunt


--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]