stl c++ 项目中的字符串类
String class in stl c++ project
是否可以在c ++ stl项目中使用String.cpp和String.h创建String类?
String.h
#include <string>
class String {
public:
static std::string Replace(const std::string& str, const std::string& oldValue, const std::string& newValue);
};
存在编译错误,除非将类重命名为其他名称,例如 Stringy
在 C++ 中使用命名空间,而不是只有静态成员的类。
#include <string>
namespace String {
std::string Replace(const std::string& str, const std::string& oldValue, const std::string& newValue);
};
您需要从类声明中删除静态,然后您发布的代码就可以正常工作。