Segmentation Fault when stepping in

Compiler: mingw

OS: windows XP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
    #include <iostream>

    class DataType1 {
    private:
      int d1;
      int d2;
    public:
      DataType1() : d1(0), d2(1) {}
      DataType1(int x, int y) : d1(x), d2(y) { }
      DataType1(const DataType1& data) : d1(data.d1), d2(data.d2) {}
      int getD1() const { return d1; }
      int getD2() const { return d2; }
      const DataType1 operator+(const DataType1& data) const {
        return DataType1(d1 + d1, d2 + d2);
      }
    };

    class Abstract {
      public:
      virtual const DataType1 getResult() const = 0;
    };

    class A : public Abstract {
    private:
      DataType1 *aPtr;
    public:
      A() : aPtr(new DataType1(1, 1)) {}
      A(const A& a) : aPtr(new DataType1(*a.aPtr)) {}
      A(const DataType1& data) : aPtr(new DataType1(data)) {}
      virtual ~A() { delete aPtr; }
      virtual const DataType1 getResult() const {
        return DataType1(0, 1);
      }
      const DataType1 getA() const {
        return *aPtr;
      }
    };

    class B : public A {
    private:
      DataType1 *bPtr;
    public:
      B() : A(), bPtr(new DataType1(2, 1)) {}
      B(const B& data) : A(data.getA()), bPtr(new DataType1(*data.bPtr)) {}
      B(const A& a, const DataType1& data) : A(a), bPtr(new DataType1(data)) {}
      ~B() { delete bPtr; }
      const DataType1 getResult() const {
        return getA() + *bPtr;
      }
      const DataType1 getB() const {
        return *bPtr;
      }
    };

in main:
1
2
    Abstract *absPtr = new B(A(DataType1(3, 5)), DataType1(4,5));
    DataType1 var1 = absPtr->getResult();

The first problem is that when I use debugger to see value of absPtr->getResult() and var1, they are different.

The second problem is that when I try to step into this line, DataType1 var1 = absPtr->getResult();, I encounter segmentation fault. The first function stepped into is DataType1(int, int).
Topic archived. No new replies allowed.