Multiple Inheritance and Function Problem

Okay so I'm having an issue with my game, nothing big, and I've patched it haphazardly. I would very much like to understand why it doesn't work though.

The problem begins here:

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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
class img{
protected:

public:
    virtual size get_size() {
      return return_size(f_w,f_h);
    }
    virtual void teleport(float tx, float ty) {
      x = tx;
      y = ty;
      update_off();
    }
    virtual void teleport(position temp) {
      x = temp.x;
      y = temp.y;
      update_off();
    }
    virtual position get_prev_pos() {
      return return_pos(px,py);
    }
    virtual position get_position() {
      position temp;
      temp.x = x;
      temp.y = y;
      return temp;
    }
};
class animate: public img{
//nothing relevant
};
class guy: public animate {
//nothing relevant
};
class test: public guy {
  protected:
    float actual_x;
    float actual_y;
    float actual_sx;
    float actual_sy;
    float offsetx;
    float offsety;
    float imageoffx;
    float imageoffy;
  public:
    void set_actual_stuff(int truesx, int truesy,int offx, int offy) {
      actual_sx = truesx;
      actual_sy = truesy;
      offsetx = offx;
      offsety = offy;
      imageoffx = (f_w - truesx) / 2 + offsetx;
      imageoffy = (f_h - truesy) / 2 + offsety;
      cout << "\nimageoffx = " << imageoffx;
      cout << "\nimageoffy = " << imageoffy;
    }
    void teleport(int first, int second) {
      cout << "CHANGE";
      x = first - imageoffx;
      y = second - imageoffy;
      update_off();
    }
    position get_overpos() {
      return return_pos(x,y);
    }
    size get_oversize() {
      return return_size(f_w,f_h);
    }
    position get_position() {
      return return_pos(x + imageoffx,y + imageoffy);
    }
    position get_prev_pos() {
      return return_pos(px + imageoffx,py + imageoffy);
    }
    size get_size() {
      return return_size(actual_sx,actual_sy);
    }
};


as you can see I've derived test from guy from animate from img, which holds the virtual functions

get_size() {

teleport(float tx, float ty) {

teleport(position temp)

get_prev_pos()

get_position()

now the rest of the problem happens here:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
bool handle_bottom_collide(img& first, img& second, bool bounce = false) {
  if(collide(&first,&second)) {
    if(first.get_prev_pos().y + first.get_size().y <= second.get_prev_pos().y) {  // bottom collides
      first.teleport(first.get_position().x,second.get_position().y - first.get_size().y);
      cout << "\nj3\n";
      if(bounce) {
        first.jmp_vel(first.get_vel().x,first.get_vel().y * -1);
      }
      else {
        first.jmp_vel(first.get_vel().x,second.get_vel().y + .5);
      }
      first.chng_jmpble(true);
    return true;
    }
  }
  return false;
}


The function uses the image functions even though they are overwritten virtual functions in the test class, should I just use a template to change the test classes?

As it stands I have overloaded the handle_bottom(and top and right and left)_collide functions with a test& first for the first parameter. What am I missing, if anything?
Something is very wrong with the naming pattern, here. img->animate->guy->test? Whatever.

I don't understand what the problem is. Do you want to call img::get_size() even when first is a test?
Last edited on
haha, sorry about that, the test is only supposed to be temporary, the only reason it's there is to fix my collision detection system =D.

Moving on, the problem is that it calls the img functions instead of the test functions if I am using an img reference, I was under the impression that because the functions are virtual it would call the highest function .
(where highest means the closest to the class the instance is a member of)
test::teleport() doesn't have the same signature as img::teleport().
Oh wow... I apologize for wasting your time... I feel like an idiot. Thank you though!
Topic archived. No new replies allowed.