Topic: Explicit call to a pure virtual function


Author: "=?ISO-8859-1?Q?Jos=E9_Couto?=" <jcouto@ctv.es>
Date: 1997/03/09
Raw View
Hello.

It is allowed to make an explicit call to a pure virtual funcion? See
the following code:

class abstract
{
public:
   virtual void pure_virtual_func() = 0;
};

class concrete : public abstract
{
public:
   virtual void pure_virtual_func()
   {
   }
};

int main()
{
   concrete c;

   c.abstract::pure_virtual_func(); // Should this be disallowed?

   return 0;
}

This code compiles under BC++ 4.5, although it produces an error
while trying to link the program. I think the compiler has enough
information to give a compiler-time error. Does the standard say
anything about it? Is there any reason to allow the previous code?

Thank you in advance.

______________________________________________________________________

                                                            Jose Couto
                                                 e-mail: jcouto@ctv.es
______________________________________________________________________
---
[ 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: Marcelo Cantos <marcelo@mds.rmit.edua.au>
Date: 1997/03/11
Raw View
"Jos=E9 Couto" <jcouto@ctv.es> writes:

> It is allowed to make an explicit call to a pure virtual funcion?...

Yes, it is also legal to supply a body for one!  The only
distinguishing feature of pure functions is that descendant classes
*must* override them, other than that, there are no special
restrictions on how to declare, define or use them.


--=20
______________________________________________________________________
Marcelo Cantos, Research Assistant             marcelo@mds.rmit.edu.au
Multimedia Database Systems Group, RMIT__/_      _  Tel 61-3-9282-2497
723 Swanston St, Carlton VIC 3053    Aus/ralia ><_> Fax 61-3-9282-2490
                                       /
Acknowledgements: errors - me; wisdom - God; funding - RMIT
---
[ 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: tony@online.tmx.com.au (Tony Cook)
Date: 1997/03/11
Raw View
=?ISO-8859-1?Q?Jos=E9_Couto?= (jcouto@ctv.es) wrote:
: Hello.

: It is allowed to make an explicit call to a pure virtual funcion? See
: the following code:

: class abstract
: {
: public:
:    virtual void pure_virtual_func() = 0;
: };

: class concrete : public abstract
: {
: public:
:    virtual void pure_virtual_func()
:    {
:    }
: };

: int main()
: {
:    concrete c;

:    c.abstract::pure_virtual_func(); // Should this be disallowed?

:    return 0;
: }

: This code compiles under BC++ 4.5, although it produces an error
: while trying to link the program. I think the compiler has enough
: information to give a compiler-time error. Does the standard say
: anything about it? Is there any reason to allow the previous code?

You are allowed to define a pure virtual function, so the compiler
allows you to call one.

This allows you to provide some base functionality in the base class
but still required a derived class to override it.

--
        Tony Cook - tony@online.tmx.com.au
                    100237.3425@compuserve.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                             ]