ここに私の問題があります: 基本クラスから継承するクラスで呼び出したい .h ファイルで定義された仮想メソッドがあります。残念ながら、派生クラスのメソッドは呼び出されません。私がやろうとしていることを実装するためのより良い方法はありますか?
#ifndef ofxBASE_SND_OBJ
#define ofxBASE_SND_OBJ
#include "ofConstants.h"
class ofxBaseSndObj {
public:
virtual string getType(){}
string key;
};
#endif
これが私の話題のクラスです
#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()); // doesn't get called!
return s;
}
次に、別のクラスで次のように呼び出します。
string ofxSndObj::createFilter(ofxBaseSndObj obj)
{
string str = obj.getType();
if(str.compare("ofxSOBuzz") == 0)
{
printf(" all is well ");
}
}
上記のメソッドでは、すべてが ofxBaseSndObj オブジェクトを拡張する多くの種類のオブジェクトの 1 つを渡すことができる必要があります。提案や指針をいただければ幸いです。ありがとう!