Here is my problem: I have a virtual method defined in the .h file that I want to call in a class that inherits from the base class. Unfortunately, the method in the derived class is not called. Is there a better way to implement what I'm trying to do?
#ifndef ofxBASE_SND_OBJ #define ofxBASE_SND_OBJ #include "ofConstants.h" class ofxBaseSndObj { public: virtual string getType(){} string key; }; #endif
Here is my buzz class
#ifndef OFXSO_BUZZ #define OFXSO_BUZZ #include "ofxBaseSndObj.h" class ofxSOBuzz : public ofxBaseSndObj { public: string getType(); }; #endif
ofxSOBuzz.cpp
string ofxSOBuzz::getType() { string s = string("ofxSOBuzz"); printf(" ********* returning string type %s", s.c_str());
Then in another class, I try to call it like this:
string ofxSndObj::createFilter(ofxBaseSndObj obj) { string str = obj.getType(); if(str.compare("ofxSOBuzz") == 0) { printf(" all is well "); } }
In the above method, I need to be able to pass one of many kinds of objects that extend the xBaseSndObj object. Any suggestions or pointers would be greatly appreciated. Thanks!
c ++ inheritance oop
Joshua noble
source share