[問題] struct function (已解決)
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
G++
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
Eigen
問題(Question):
想要把input struct的function 放到header file去
可是分開就不能compile,想問要header file要怎麼編寫?
下面是可以執行的code,想把f函數移到header file中。
我GOOGLE了,說可以先用typedef之類的,可是我typedef從沒成功過...
程式碼(Code):(請善用置底文網頁, 記得排版)
http://codepad.org/R0xt9tWL
補充說明(Supplement):
解決方式如下:
我把它拆成以下兩個file..
**************** struct_f.h ****************
using namespace Eigen;
MatrixXd f(uLSIF_para& uLSIF_parameters)
{
return uLSIF_parameters.width_candidates;
}
**********************************************
**************** test.cpp ****************
#include "Eigen/Dense"
#include "Eigen/Core"
using namespace Eigen;
typedef struct
{
MatrixXd width_candidates;
size_t posclass;
} uLSIF_para;
#include <time.h>
#include <iostream>
#include "struct_f.h"
using namespace std;
int main()
{
srand((unsigned int)time(NULL));
MatrixXd width_candidates(1, 13);
width_candidates << 0.1, 0.2, 0.3, 0.4, 0.5, 0.6,
0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3;
size_t posclass = 1;
uLSIF_para uLSIF_parameters =
{
width_candidates,
posclass
};
cout << f(uLSIF_parameters) << endl;
return 0;
}
*******************************************
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 36.238.86.146
推
02/22 01:19, , 1F
02/22 01:19, 1F
已補上...
→
02/22 02:10, , 2F
02/22 02:10, 2F
→
02/22 02:11, , 3F
02/22 02:11, 3F
→
02/22 02:12, , 4F
02/22 02:12, 4F
我完全看不懂你在說什麼...怎麼辦...
→
02/22 02:22, , 5F
02/22 02:22, 5F
推
02/22 13:26, , 6F
02/22 13:26, 6F
我只是想分成兩個檔案,一個檔案太長了...
不知道拆成兩個檔案還有什麼好處嗎?
→
02/22 14:40, , 7F
02/22 14:40, 7F
→
02/22 14:40, , 8F
02/22 14:40, 8F
→
02/22 15:04, , 9F
02/22 15:04, 9F
※ 編輯: celestialgod 來自: 36.238.86.146 (02/22 15:53)