如果这是一个重复的问题,请告诉我,不要downvote,我是
Android-native开发的新手.我想通过使用Android本机代码创建一个ArrayList,我尝试了以下内容:
#include
#include
#include
template
extern "C"{ //here it is showing **error expected unqualified-id before string constant**
std::vector list;
JNIEXPORT void JNICALL Java_com_example_nativetestapp_NativeList_add(
JNIEnv * env, jobject obj, T t) {
list.push_back(t);
}
JNIEXPORT jboolean JNICALL Java_com_example_nativetestapp_NativeList_remove(
JNIEnv * env, jobject obj, int pos) {
if (pos > list.size() - 1 || pos < 0)
return false;
return list.erase(list.begin() + pos) != NULL ? true : false;
}
JNIEXPORT jint JNICALL Java_com_example_nativetestapp_NativeList_size(
JNIEnv * env, jobject obj) {
return list.size() == NULL ? 0 : list.size();
}
JNIEXPORT jint JNICALL Java_com_example_nativetestapp_NativeList_get(
JNIEnv * env, jobject obj, int pos) {
return list[pos];
}
JNIEXPORT jboolean JNICALL Java_com_example_nativetestapp_NativeList_contains(
JNIEnv * env, jobject obj, T t) {
for (int var = 0; var < list.size(); var++) {
if(t==list[var])
return true;
}
return false;
}
JNIEXPORT jboolean JNICALL Java_com_example_nativetestapp_NativeList_remove(
JNIEnv * env, jobject obj, T t) {
for (int var = 0; var < list.size(); var++) {
if(t==list[var]){
list.erase(list.begin()+var);
return true;
}
}
return false;
}
};
但我仍然坚持代码中提到的错误.如果我之后放了一个分号
template;
然后在这一行后我得到一个新的错误:
cannot resolve T symbol.