Is there a way to pass a variable from a constructor of a derived class to the constructor of the base class?

I'm looking for a way to pass the variable 'pos' to the constructor of the class 'Entity' from its derived class 'Paddle'. I know that in this case I can simply create the variable where I pass it, but I'd like to know if there's a solution for cases in which I need to pass the variable through few operations before passing it to the constructor of the base class.

Paddle() : Entity(pos, size, Float2D(0, _velocity))
{
Float2D pos;
pos.x = side ? (DISPLAY_SIZE.y - size.y - _distance) : _distance;
pos.y = DISPLAY_SIZE.y / 2;
}

Thanks in advance for the help.

BTW, the Preview button and the Format options don't seem to be working for me. Does that only happen to me, or do other people notice that too?
Last edited on
You can do this, but ...
1
2
3
4
5
6
7
Paddle()
: Entity( Float2D( side ? (DISPLAY_SIZE.y - size.y - _distance) : _distance,
                   DISPLAY_SIZE.y / 2 ),
          size,
          Float2D(0, _velocity) )
{
}


you'd like to have "operations":
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Float2D operations()
{
  Float2D pos;
  pos.x = side ? (DISPLAY_SIZE.y - size.y - _distance) : _distance;
  pos.y = DISPLAY_SIZE.y / 2;
  return pos;
}


Paddle()
: Entity( operations(),
          size,
          Float2D(0, _velocity) )
{
}



Overall, the example that you do show raises questions about where all those data bits come from.
Thanks keskiverto, I guess that solves it. I hoped that there would be a way to do that inside the constructor itself. But it's a perfectly working solution nonetheless.
Topic archived. No new replies allowed.