C/C++ 语法
extern “C”的作用详解
.hpp与.h区别
JNI详解---从不懂到理解
android jni/cmake
Android NDK 开发之 CMake 必知必会
Android Studio NDK CMake 指定so输出路径以及生成多个so的案例与总结
cmake手册
.h .hpp的理解
.h是通用的c/c++头文件,是一种兼容的写法,但是要手动区分是C工程还是C++工程
for example .h :
#ifndef MY_HEADER_H
#define MY_HEADER_H
#ifdef __cplusplus
extern "C"
{
#endif
void myCFunction() ;
#ifdef __cplusplus
} // extern "C"
#endif
#endif // MY_HEADER_H
.hpp
#ifndef MY_HEADER_HPP
#define MY_HEADER_HPP
extern "C"
{
#include "my_header.h"
}
#endif // MY_HEADER_HPP
and,把.h拆出来了
#ifndef MY_HEADER_H
#define MY_HEADER_H
void myCFunction() ;
#endif // MY_HEADER_H
这样,.h单独拿出来,.hpp里可以针对c++场景对C的实现做兼容,代码更清爽了。没有if else的判断。
参考:
https://stackoverflow.com/questions/152555/h-or-hpp-for-your-class-definitions
补充一点:extern是c++兼容c的产物,c++有重载实现,方法签名包含传参类型和个数,C语言是没有重载的概念的。
virtual 虚函数的理解
virtual是c++实现多态的机制
B继承A,假如B有方法fun(),A重写了fun(),
B b = new B;
A a = b;
A.fun();
调用的是A的fun方法,这点和java不同,但是fun()方法前加了virtual,则A.fun()调用的是B.fun()
网友评论