Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Is SoundBufferRecorder made to be subclassed ?  (Read 5416 times)

0 Members and 3 Guests are viewing this topic.

deadalnix

  • Newbie
  • *
  • Posts: 45
    • View Profile
Is SoundBufferRecorder made to be subclassed ?
« on: December 02, 2011, 11:56:18 pm »
I'm not sure it make that much sense to subclass this, as long as all useful things are private.

If it is not meant to be subclassed, callback should be declared non virtuals.

If it is meant to be subclassed, internal buffer should be protected and/or callbacks too (to allow subclasses to recall parent's callback).

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Is SoundBufferRecorder made to be subclassed ?
« Reply #1 on: December 03, 2011, 10:00:14 am »
Why would you subclass it? If you want to implement your own sound recorder, inherit from sf::SoundRecorder directly.
Laurent Gomila - SFML developer

deadalnix

  • Newbie
  • *
  • Posts: 45
    • View Profile
Is SoundBufferRecorder made to be subclassed ?
« Reply #2 on: December 03, 2011, 12:30:48 pm »
That was what I thought. Even made private virtual function can still be redefined in subclasses. So I guess we should make callback non virtual in this class.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Is SoundBufferRecorder made to be subclassed ?
« Reply #3 on: December 03, 2011, 02:20:28 pm »
It is virtual, wether I use the 'virtual' keyword or not, because it is declared virtual in the base class. You can't stop a virtual function from being virtual.
Laurent Gomila - SFML developer

deadalnix

  • Newbie
  • *
  • Posts: 45
    • View Profile
Is SoundBufferRecorder made to be subclassed ?
« Reply #4 on: December 04, 2011, 04:00:31 pm »
Yes, but you can prevent someone to try to redefine it in subclasses.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Is SoundBufferRecorder made to be subclassed ?
« Reply #5 on: December 04, 2011, 06:16:17 pm »
How? Like I said, I can't. And anyway, if someone wants to do that for a very good reason, then... he can do it, SFML won't blow up ;)
Laurent Gomila - SFML developer

deadalnix

  • Newbie
  • *
  • Posts: 45
    • View Profile
Is SoundBufferRecorder made to be subclassed ?
« Reply #6 on: December 05, 2011, 12:12:03 am »
You can rediefine virtual function in subclasses even if they are private. You cannot call them, but can define them.

Well it is a strangeness, but it is confusing, not dangerous.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Is SoundBufferRecorder made to be subclassed ?
« Reply #7 on: December 05, 2011, 07:48:11 am »
Quote
You cannot call them

Which is good, if they are not meant to be called.

But anyway, what do you suggest?
Laurent Gomila - SFML developer

deadalnix

  • Newbie
  • *
  • Posts: 45
    • View Profile
Is SoundBufferRecorder made to be subclassed ?
« Reply #8 on: December 05, 2011, 05:59:42 pm »
I suggest one of thoses :

1/ Make mySamples protected, so callback function can use it when overloaded. With such a decision, SoundBufferRecorder can be subclassed in a usefull way.

Callback function could be delared protected too if we consider that the subclass can call SoundBufferRecorder's callback.

2/ Make callback's function non virtual. This will not change anything at runtime, because thay are called from SoundRecorder, so the function call will be virtual anyway.

But it makes it clear that the class is not meant to be overriden.

Let's explain what make me start this topic. I did look at the SoundBufferRecorder class and saw that it has some virtual function. So I wondered what I could do to subclass SoundBufferRecorder in a usefull way. And nothing that couldn't be done with SoundRecorder directly, because every additions in SoundBufferRecorder are private. At the end, this virtual stuff isn't usefull and can confuse a person reading the header file.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Is SoundBufferRecorder made to be subclassed ?
« Reply #9 on: December 05, 2011, 06:09:45 pm »
I have a different point of view. I always write 'virtual' in front of virtual functions, whether it makes sense or not in the derived class, because they are virtual.

If you can't find anything useful to do with SoundBufferRecorder as a base class, then don't use it. It's not meant to be used like this. The tutorial and documentation make it clear enough I think.

It will only confuse people like you, that try to derive SoundBufferRecorder for fun. People who have an actual problem to solve will most likely not get blocked by this "issue".
Laurent Gomila - SFML developer

 

anything