Chesnokov Yuriy
Chesnokov Yuriy

Reputation: 1838

String class in stl c++ project

Is it possible to create String class with String.cpp and String.h in c++ stl project?

String.h

#include <string> 
class String {
public:
    static std::string Replace(const std::string& str, const std::string& oldValue, const std::string& newValue);
};

There are compilation errors unless the class is renamed to something else like Stringy

Upvotes: 0

Views: 161

Answers (2)

user1804599
user1804599

Reputation:

Instead of a class with only static members, you use a namespace in C++.

#include <string>

namespace String {
    std::string Replace(const std::string& str, const std::string& oldValue, const std::string& newValue);
};

Upvotes: 4

Ryan Guthrie
Ryan Guthrie

Reputation: 688

You need to remove the static from the class declaration and your posted code works just fine then.

Upvotes: 3

Related Questions