0

I am working on one of the STK programs using a Sine Oscillator callback. I am having issues when creating an object from my ToneGen class that inherits from the Generator Class due to a Virtual function in the Generator class that causes my ToneGen class to abstract. i Have tried pointers but it seems to be causing issues getting the data to the appropriate method. If i use pointers my code breaks here in the ToneGen.h file

void setRate( StkFloat rate ) { rate_ = rate; };

Otherwise without pointers i get this error

src\crtToneGen.cpp(36): error C2259: 'stk::ToneGen' : cannot instantiate abstract class
          due to following members:
          'stk::StkFrames &stk::Generator::tick(stk::StkFrames &,unsigned int)' : is abstract
          C:\VS10 Projects\StkNewInst\crtToneGen\include\Generator.h(43) : see declaration of 'stk::Generator::tick'

Here is the Virtual Function in the Generator Class

virtual StkFrames& tick( StkFrames& frames, unsigned int channel = 0 )=0;

Is there anyway to avoid this, i have tried several other techniques on other post but have not had any luck yet.

The Code i am modifying can be found here

I am doing this on VisualStudio 2010 windows 7 32 bit

SingerOfTheFall
  • 29,228
  • 8
  • 68
  • 105
Alex
  • 11
  • 3

1 Answers1

0
stk::StkFrames &stk::Generator::tick(stk::StkFrames &,unsigned int)

Is abstract, and needs to be implemented in your derived class

class ToneGen: public stk::Generator
{
  stk::stkFrames& tick(stk::StkFrames& frames,unsigned int something)
  {
     return stk::stkFrames(); // Don't do this, return something useful.
  }
}

You have to implement this function in your derived class as the base class provides no functionality for this method. It's declaration in the stk header would be:

stk::StkFrames &stk::Generator::tick(stk::StkFrames &,unsigned int) = 0;
Aesthete
  • 18,622
  • 6
  • 36
  • 45
  • So i put the first block in the Tone Gen header: static StkFrames table_; StkFloat phaseOffset_; unsigned int iIndex_; StkFloat alpha_; }; stk::StkFrames& tick(stk::StkFrames& frames,unsigned int channel) { return frames; } inline StkFloat ToneGen :: tick( void ) but when i put the second declaration in the stk header i received an error that the qualifier must be a part of the base class stk::StkFrames. I implemented it in the StkFrames class in the stk Header, not really sure where that would go. Thanks – Alex Sep 17 '12 at 11:38
  • Put it in a pastebin and link it here – Aesthete Sep 17 '12 at 12:04
  • http://pastebin.com/0FhecUn8 .(in Stk.h StkFrames Class)I tried changing it to Generator::tick_(etc...) but that did not work either, should i be doing something in my crtToneGen class, that is where i am having trouble with the ToneGen tone; object. i am at a loss on this one. https://ccrma.stanford.edu/software/stk/SineWave_8h_source.html This link is what i based my tonegen.h class off of and on the stk tutorial page i based the crtTonegen.cpp off of and https://ccrma.stanford.edu/software/stk/crealtime.html is what i based my crtToneGen.cpp file off of – Alex Sep 17 '12 at 13:48
  • The other classes i am using are Generator.h (as is) and SineWave.cpp (unchanged except for the class name) – Alex Sep 17 '12 at 13:51
  • Also Any advice on integrating this into a Windows application instead of a Command line .exe would be greatly appreciated, Thanks again – Alex Sep 17 '12 at 14:19
  • Fixed it, after rebuilding and reconfiguring the session it worked fine. I can still use some tips on GUI implementation if any one has any. Thanks again – Alex Sep 18 '12 at 12:17
  • Great. Well this answers deals directly with your first question and the error messages you had regarding abstract instantiation attempts. If you have further design questions or problems I suggest starting new questions. – Aesthete Sep 18 '12 at 12:24