I was searching SVM libraries and encountered BudgetedSVM.
In the source code, I found an unusual usage, just like this:
#sample.h
#ifndef SAMPLE_H
#define SAMPLE_H
//no header included or namespace declared here
#ifdef __cplusplus
extern "C" {
#endif
//no header included or namespace declared too
class Sample: public Parent
{
public:
Sample();
~Sample();
type0 fun(type1 val1, type2 val2);
...
};
#ifdef __cplusplus
}
#endif
#endif // SAMPLE_H
As seen, no extra header or namespace is needed in the header, which all are in the cpp file.
Here are my thoughts:
Why does
extern "C"
, which usually is used for C interfaces, group the C++ class? Is the usage in this way good for something?Even if
type0
,type1
andtype2
appeared, their own headers are not included here, but in the cpp file (e.g. sample.h). When I call the classSample
, however, I have to include these headers (e.g.type0.h
,type1.h
,type2.h
), which seems inconvenient.