faceplusplus / facepp_cpp_sdk Goto Github PK
View Code? Open in Web Editor NEWFaceppApi_SDK_C++_XCode
FaceppApi_SDK_C++_XCode
// FaceppApi.hpp
#include <stdio.h> // [1]
class FaceppApi
{
protected:
const char * key; // Api_key [2]
const char * secret; // Api_secret
};
[1] 一般使用 #include <cstdio>
代替 #include <stdio.h>
The ".h" headers dump all their names into the global namespace, whereas the newer forms keep their names in namespace std. Therefore, the newer forms are the preferred forms for all uses except for C++ programs which are intended to be strictly compatible with C.
@see Standard C++ C-Library Subset Header Strategy
[2] 在类中使用指针的危险性
在 FaceppApi
中使用指针为浅复制,当使用常量指针转递参数给构造函数没有问题,作为 C++ 的开发者会选择 std::string
,为了适配库,可能以 std::string.c_str()
形式传递参数给构造函数,往往出现参数已经失效,引用了一个无效的指针。
// Utils/CurlPost.hpp
#ifndef CurlPost_hpp
#define CurlPost_hpp
#include <iostream>
#include <map>
using namespace std; // [3]
class CurlPost
{
public :
void doPost(const char * URL, map<const char* , const char*> params); // [4]
};
#endif /* CurlPost_hpp */
[3] 在头文件中引入命名空间 std
容易引发名字冲突
难以保证我们在开发过程中不效仿标准库的命名规则,在头文件中引入命名空间 std
,只要包含了它,后续所有代码都表明使用命名空间内的代码,万一自己命名了相同的标识符会产生冲突。
[4] 与类成员无关的函数可以独立
在类 CurlPost
中的 doPost
并没有使用类的任何数据,这个方法导致在调用处创建一个临时对象,将它声明为静态函数(CurlPost::doPost(...)
)或命名空间(curlpost::doPost(...)
)内的自由函数,免于创建临时对象。
[5] 建议: 库加上自己的命名空间,免于与用户代码冲突。
修改如下
*((stringstream*) content) << data;
为什么cmakelists.txt相关设置完成后,无法链接到静态库?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.