I have an Android project in Eclipse. In the jni
folder I create Store.h
where I just define:
class Store{
};
And in Store.c
I type:
#include "Store.h"
And I get error in the definition of class Store
but if I use Store.hpp
and Store.cpp
files instead of .h
and .c
I don't get any errors. Could anyone explain why? Which format is better to use in this case and why?
Use .cpp
for C++ files, and .c
for C files. .h
and .hpp
are both fine for any C++ header files - but .h
is more common.
The reason your code is not compiling when the file has a .c
extension, is because a C compiler is being used based on the file extension. When you rename it to have a .cpp
extension, a C++ compiler is used and the code compiles fine.