| Title: | C++ | 
| Notice: | Read 1.* and use keywords (e.g. SHOW KEY/FULL KIT_CXX_VAX_VMS) | 
| Moderator: | DECCXX::AMARTIN | 
| Created: | Fri Nov 06 1987 | 
| Last Modified: | Thu Jun 05 1997 | 
| Last Successful Update: | Fri Jun 06 1997 | 
| Number of topics: | 3604 | 
| Total number of notes: | 18242 | 
Hello
I have a customer running OSF 3.2c and Digital C++ version 5.4-006
He states that the c++ compiler should be able to pick up the described
programming error using abstract classes.
I have tested it using visual c++ 4.1 on an alpha running NT and it does not
pick up the error either until runtime.
Should the compiler find the programming error?
Regards
Poul Erik Thomsen
Digital Denmark
     
-------------------------From the customer--------------------------
     
The DEC C++ compiler seems to have a bug, when dealing with abstract base 
classes and classes derived hereof.
     
    The small code example is compiled and linked by the Dec
    C++ compiler without problems, whereas the GNU C++ compiler 
    gives an error message.
     
Code example
============-
     
#include <iostream.h>
     
// Abstract base class
     
class B
{
public:
   virtual void Dump() = 0;
};
     
// Class derived from base class
// OK to instanciate as BD defines Dump() method
     
class BD : public B
{
public:
   void Dump() { cout << "BD::Dump()" << endl; };
};
     
// Class containing instances of B
// Should give compiler error, as B is abstract
     
class BC
{
public:
   B b[5];
};
     
main()
{
   BD * pBD = new BD;
   BC * pBC = new BC;
     
   pBD->Dump();         // OK
     
   pBC->b[0].Dump();    // Gives segmentation violation when run
}
     
     
Compile code example
---------------------------------------------------------
cxx -o x x.cxx
     
Run program (gives segmentation violation) 
---------------------------------------------------------
x
BD::Dump()
Segmentation fault (core dumped)
     
Compile code example with GNU C++
---------------------------------------------------------
g++ -o x x.cxx
x.cxx:27: cannot declare field `BC::b' to be of type `B' 
x.cxx:27:   since the following virtual functions are abstract: 
x.cxx:27:       void B::Dump()
     
                   
| T.R | Title | User | Personal Name | Date | Lines | 
|---|---|---|---|---|---|
| 3413.1 | customer is right, it should give an error... | DECC::J_WARD | Tue Jan 28 1997 09:23 | 12 | |
| 
When version 6.0 of the DEC C++ compiler is released,
the following error will be given:
"t.cxx", line 26: error: array of abstract class is not allowed
     B b[5];
       ^
1 error detected in the compilation of "t.cxx".
cxx currently only gives an error if b is not an array type ... this
is a bug.
 | |||||