delorie.com/archives/browse.cgi | search |
Mailing-List: | contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm |
Sender: | cygwin-owner AT sourceware DOT cygnus DOT com |
Delivered-To: | mailing list cygwin AT sourceware DOT cygnus DOT com |
Reply-To: | <ifarquha AT ihug DOT co DOT nz> |
From: | "Ian Farquharson" <ifarquha AT ihug DOT co DOT nz> |
To: | <cygwin AT sourceware DOT cygnus DOT com> |
Subject: | This C++ code fails |
Date: | Tue, 16 Mar 1999 00:07:20 +1300 |
Message-ID: | <000001be6ed3$ff014260$c801a8c0@warpcore> |
MIME-Version: | 1.0 |
X-Priority: | 3 (Normal) |
X-MSMail-Priority: | Normal |
X-Mailer: | Microsoft Outlook 8.5, Build 4.71.2377.0 |
Importance: | Normal |
X-MimeOLE: | Produced By Microsoft MimeOLE V4.72.3110.3 |
------=_NextPart_000_0001_01BE6F40.F5FC1100 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit This small test program demonstrates a problem I am having with virtual base classes and a pointer to member. When I try to call a function in a class that has virtual base classes through a pointer to member the program crashes. I have compiled and run this same test successfully under Borland C++ 5.02 I am using cygwin B20.1 with EGCS 1.1.1 installed. You can compile the test using the command "gcc Try.cpp -o Try.exe". When the program is run I get the following output: bash-2.02$ gcc try.cpp -o try.exe bash-2.02$ ./try Calling Test1::Click directly. void Test1::Click(void) Calling Test1::Click through pointer to member. void Test1::Click(void) Calling Test2::Click directly. void Test2::Click(void) Calling Test2::Click through pointer to member. [main] D:\race\test\try.exe 1016 (0) handle_exceptions: Exception: STATUS_ACCESS _VIOLATION [main] try 1016 (0) handle_exceptions: Dumping stack trace to try.exe.core The Test2 class is using virtual base classes, unlike the Test1 class. This difference causes an exception to be thrown when the pointer to member is used. Any help would be much appreciated. ------=_NextPart_000_0001_01BE6F40.F5FC1100 Content-Type: application/octet-stream; name="Try.cpp" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="Try.cpp" /************************************************************************= ****\ * = * * Test program that demonstrates bug with virtual base classes and = pointer * * to member = * * = * * Author: Ian Farquharson (ifarquha AT ihug DOT co DOT nz) = * * = * \************************************************************************= ****/ #include <stdlib.h> #include <stdio.h> // Class declarations = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D class Base1 { public: virtual ~Base1(void); }; class Base2 { public: virtual ~Base2(void); virtual void Click(void); }; class Test1: public Base1, public Base2 // NB: = non-virtual { public: virtual ~Test1(void); virtual void Click(void); }; class Test2: virtual public Base1, virtual public Base2 // NB: virtual { public: virtual ~Test2(void); virtual void Click(void); }; // Class implementation = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D Base1::~Base1(void) { } Base2::~Base2(void) { } void Base2::Click(void) { printf("void Base2::Click(void)\n"); } Test1::~Test1(void) { } void Test1::Click(void) { printf("void Test1::Click(void)\n"); } Test2::~Test2(void) { } void Test2::Click(void) { printf("void Test2::Click(void)\n"); } // RunTest1 demonstrates a class using multiple inheritence = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D typedef void (Test1::*Test1Proc)(void); void RunTest1(void) { Test1 test; printf("Calling Test1::Click directly.\n"); test.Click(); printf("Calling Test1::Click through pointer to member.\n"); Test1Proc proc =3D &Test1::Click; (test.*proc)(); } // RunTest2 demonstrates a class using multiple virtual inheritence = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D typedef void (Test2::*Test2Proc)(void); void RunTest2(void) { Test2 test; printf("Calling Test2::Click directly.\n"); test.Click(); printf("Calling Test2::Click through pointer to member.\n"); Test2Proc proc =3D &Test2::Click; (test.*proc)(); } // main = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D int main(int, char* []) { RunTest1(); RunTest2(); return 0; } ------=_NextPart_000_0001_01BE6F40.F5FC1100 Content-Type: text/plain; charset=us-ascii -- Want to unsubscribe from this list? Send a message to cygwin-unsubscribe AT sourceware DOT cygnus DOT com ------=_NextPart_000_0001_01BE6F40.F5FC1100--
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |