abstract classes not detected by compiler

From: Bjorn (bjed_at_tss.teleca.se)
Date: 10/25/04


Date: Mon, 25 Oct 2004 15:14:44 +0200

I'm using interfaces in C++ by declaring classes with only pure virtual
methods. If then someone wants to implement the interface they
needs to inherit from the class. If the implementing class forgets to
implement some method I normally get a compile error(if the class is created
in some way of course). When using the Visual
Studio 6 compiler however, it does not generate a compile error in this
case:

- I have a implementing class A that inherits from an interface class. It
has not implemented all methods.
- The implementing class A is declared as an array in a container class. The
container class is created with new.

The compiler do not generate any errors, but I will of course get a runtime
error when a method with no implementation is called("pure function call" or
something). If the container class declares A as a pointer(and performs new
on it) or as a non-array variable, then the compiler generates compile
errors, but not if it is declared as an array.

So, my question is: is it a compiler fault, if it does not find out that an
abstract class is created(which is the case here since all methods are not
implemented)? Or should it be considered as normal that the compiler can not
find out cases like this(i.e more complicated cases).

/Bjorn



Relevant Pages

  • Re: abstract classes not detected by compiler
    ... > needs to inherit from the class. ... it does not generate a compile error in this ... > - I have a implementing class A that inherits from an interface class. ... The compiler errors out as follows - ...
    (comp.lang.cpp)
  • Re: abstract classes not detected by compiler
    ... > needs to inherit from the class. ... > - I have a implementing class A that inherits from an interface class. ... > - The implementing class A is declared as an array in a container class. ... > The compiler do not generate any errors, but I will of course get a runtime ...
    (comp.lang.cpp)
  • Re: C++: compile time conditional inheritance
    ... Doru-Catalin Togea writes: ... > In my application I have objects which must inherit any ONE of the Module ... > How do I tell the compiler how to chose a particular class at compile ... I'm thinking that maybe by declaring ...
    (comp.os.linux.development.apps)
  • Re: MFC and c++ problems
    ... compiler to generate code that is architecturally nonsensical. ... So a design in which a control has any syntactic knowledge of any container of itself ... GetParent->SendMessage is the interface of choice, ...
    (microsoft.public.vc.mfc)
  • Re: Win32 API and gfortran
    ... write out a module containing only interface blocks and compile the ... that the /iface switches and ATTRIBUTES directives change the compiler ... arguments are passed in the normal Fortran way ...
    (comp.lang.fortran)