[問題] 傳入一個function pointer
小弟目前正在使用C++ 的一套Graphcut Lib MRF
裡面在呼叫mrf這個class的時候是長這樣:
DataCost *data = new DataCost(DataTerm);
//DataTerm 是一個int指標
SmoothnessCost *smooth = new SmoothnessCost(Smoothness);
//這裡是我的問題
//Smoothness 是一個回傳 float的function
要求是長這樣 float foo(int a, int b, int c, int d)
//以下不重要....
EnergyFunction *eng = new EnergyFunction(data,smooth);
//For Graph-cuts with expansion algorithm:
float t;
MRF* mrf = new Expansion(Width,Height,2,eng);
我想要把這段code包到一個class A中去使用
但是我在A之中寫了一些public function
float A_Smooth(int a, int b, int c, int d) {return xxx;};
void Do()
{
DataCost *data = new DataCost(DataTerm);
SmoothnessCost *smooth = new SmoothnessCost(A_Smooth);
EnergyFunction *eng = new EnergyFunction(data,smooth);
//For Graph-cuts with expansion algorithm:
float t;
MRF* mrf = new Expansion(Width,Height,2,eng);
mrf->initialize();
...
};
會出現compile error:
function call missing argument list; use '&A::A_Smooth' to create
a pointer to member
目前的問題是 A 之中有一個物件 a_obj負責提供資料給A_Smooth
如果把這個物件設為Static 然後把A_Smooth拿到 class外面變成普通funciton
變成 float A_Smooth(int a, int b, int c, int d) {return A::obj[a][b];}
就可以正確compile, 但是這樣同時間只能有一個class A 呼叫 Do(),
請問有辦法保持讓A_Smooth放在class A之中 但還是能成功Compile的寫法嗎?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.34.171.29
→
04/18 00:08, , 1F
04/18 00:08, 1F
→
04/18 00:09, , 2F
04/18 00:09, 2F
→
04/18 01:01, , 3F
04/18 01:01, 3F
→
04/18 01:01, , 4F
04/18 01:01, 4F
→
04/18 11:58, , 5F
04/18 11:58, 5F
→
04/18 11:59, , 6F
04/18 11:59, 6F
→
04/18 12:00, , 7F
04/18 12:00, 7F
→
04/18 15:03, , 8F
04/18 15:03, 8F
→
04/18 15:03, , 9F
04/18 15:03, 9F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章