O
oliver
My code is as follow. I know that I should use virtual destructor in
A. Why the following code gave me the following complain.
*** glibc detected *** ./private: free(): invalid pointer:
0x0000000001a92018 ***
The environment is Ubuntu 10.10 amd64 with gcc "gcc version 4.4.5
(Ubuntu/Linaro 4.4.4-14ubuntu5)"
1 using namespace std;
2 #include <iostream>
3
4 class A
5 {
6 private:
7 int a;
8 };
9
10 class B : virtual public A
11 {
12
13 };
14
15 int main()
16 {
17 A *ptr = new B;
18 delete ptr;
19 return 0;
20 }
A. Why the following code gave me the following complain.
*** glibc detected *** ./private: free(): invalid pointer:
0x0000000001a92018 ***
The environment is Ubuntu 10.10 amd64 with gcc "gcc version 4.4.5
(Ubuntu/Linaro 4.4.4-14ubuntu5)"
1 using namespace std;
2 #include <iostream>
3
4 class A
5 {
6 private:
7 int a;
8 };
9
10 class B : virtual public A
11 {
12
13 };
14
15 int main()
16 {
17 A *ptr = new B;
18 delete ptr;
19 return 0;
20 }