このメンバー関数内の静的なデータにアクセスしたいと思います。現在、メンバー関数は静的であるため、コールバックの目的でtypdef関数ポインターを持つCで記述されたサードパーティのAPIで使用できます。以下の情報に基づいて、静的ではないクラスの他のメンバー関数内で次の関数メンバーからのデータを使用するために静的関数を作成する必要性を回避するための最良の方法は何ですか。たぶん、この静的関数を使用する方法はありますが、静的変数と非静的変数を混在させることができないことを克服する方法があります。私のコードはそのまま動作しますが、次のコールバック関数のデータにアクセスする機能がありません。
void TextDetect::vtrCB(vtrTextTrack *track, void *calldata) /*acts as a callback*/
{
/*specifically would like to take data from "track" to a deep copy so that I don't loose scope over the data withing that struct */
}
Cで記述された関連APIには、次の2行のコードがあります。
typedef void (*vtrCallback)(vtrTextTrack *track, void *calldata);
int vtrInitialize(const char *inifile, vtrCallback cb, void *calldata);
これが私のクラスのヘッダーです:
#include <vtrapi.h>
#include <opencv.hpp>
class TextDetect {
const char * inifile;
vtrImage *vtrimage;
int framecount;
public:
TextDetect();
~TextDetect();
static void vtrCB(vtrTextTrack *track, void *calldata);
int vtrTest(cv::Mat);
bool DrawBox(cv::Mat&);
};
TextDetect::TextDetect() : inifile("vtr.ini")
{
if (vtrInitialize(inifile, vtrCB /*run into problems here*/, NULL) == -1)
std::cout << "Error: Failure to initialize" << std::endl;
vtrimage = new vtrImage;
framecount = 0;
}
void TextDetect::vtrCB(vtrTextTrack *track, void *calldata) /*acts as a callback*/
{
/*specifically would like to take data from "track" to a deep copy so that I don't loose scope over the data withing that struct */
}