[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference turris::c_plus_plus

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

3413.0. "OSF Digital C++ V5.4-006 Abstract classes error?" by COPCLU::PETHOMSEN () Tue Jan 28 1997 06:12

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.RTitleUserPersonal
Name
DateLines
3413.1customer is right, it should give an error...DECC::J_WARDTue Jan 28 1997 09:2312
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.