c++结构到Java类
C++ struct to Java class
我想这样转换一个c++结构体:
typedef struct FEATUREINFO
{
string str_ID;
char* c_ID;
double* featureData;
int group;
bool bPrint;
IplImage *t_faceImg;
}FEATUREINFO;
我将使用它:
FEATUREINFO * p_featureNode = new FEATUREINFO[100];
for(int j=0; j<100 ; j++)
{
p_featureNode[j].featureData = (double*)calloc(t_featureLen,sizeof(double));
p_featureNode[j].bPrint = false;
}
在Java代码中我写了我的代码:
class FEATUREINFO
{
string str_ID;
char[] c_ID;
public Double[] featureData;
int group;
public boolean bPrint;
//IplImage *t_faceImg;
public FEATUREINFO()
{
this.featureData = new Double[1280] ;
}
} // class FEATUREINFO
并写了一个简单的代码来测试我是否成功:
FEATUREINFO[] p_featureNode = new FEATUREINFO[100];
p_featureNode[5].featureData[2] = 100.5 ; // this line will error!!! =(
Log.d(Tag_Test, "featureData :" + p_featureNode[5].featureData[2] ) ;
我是Java的初学者,请帮助我!非常感谢!
这是我的错误:https://i.stack.imgur.com/swow5.png
再次感谢!!!!!div = D
c++将每个数组元素初始化为默认状态(调用每个数组元素的默认构造函数)- Java不这样做。
你需要这样写:
FEATUREINFO[] p_featureNode = initializeWithDefaultFEATUREINFOInstances(100);
...
public static FEATUREINFO[] initializeWithDefaultFEATUREINFOInstances(int length)
{
FEATUREINFO[] array = new FEATUREINFO[length];
for (int i = 0; i < length; i++)
{
array[i] = new FEATUREINFO();
}
return array;
}
public class FEATUREINFO(){
string str_ID;
char c_ID;
double featureData;
int group;
bool bPrint;
IplImage t_faceImg;
public /*noreturntypeforconstructor*/ FEATUREINFO(String a, char b, double c, int d, bool e, IplImage f){
this.str_ID = a; // the inputs to the constructor
this.c_ID = b;
this.featureData = c;
this.group = d;
this.bPrint = e;
this.t_faceImg = f;
} // if all values arenot know before object is create sostandard constructor isused (FEATUREINFO(/*no args*/))
public String getstrID(){
return this.str_ID;
}
public String setstrID(String inputString){
this.str_ID = inputString;
} // getter and setters for each member....
} // i understand that you probably already know all of this but it was fun writing it :)
相关文章:
- 相当于 Java 中的C++结构
- 为什么像C++和Java这样的语言有一个内置的LinkedList数据结构
- Java 中的私有变量和 C++ 结构中的私有变量有什么区别?
- 在C++中实现 Java 集合层次结构
- TCP-Server以数据包结构(非Java客户端)发送文件
- 将 C++ 中的结构转换为 Java 中的类
- 如何从Java中的C DLL加载和使用结构和功能
- C++/C#/Java 中的'Class'思想是否来自 C 中的结构?
- C++和 Java 数据结构的重叠:堆栈"top"与"peek"
- 在Android应用程序(Java和XML)中使用C++结构
- JNA(Java):如何将指针数组传递给结构
- 如何使用 JNI 将结构数组从 C++ dll 返回到 Java Applet
- 模仿 java 结构中的C++并写入 byte[]
- 复制(非浅层或深层)用于C/C++/Java等同物中的结构.复制到所有成员都指向完全相同内存的变量
- 线程和消息队列体系结构.Java和C++的区别
- 在c#、c++和java中创建python弱类型结构的强类型版本
- c++结构到Java类
- c++中结构和指针的语法,相当于Java
- 如何通过套接字发送与c++兼容的Java结构体
- 哪些C++数据结构可以处理类似于Java ArrayList 'insert'?