I have a class exposing a static function in myclass.hpp
class MyClass {
public:
static std::string dosome();
};
Well, in myclass.cpp what should I write: this:
std::string MyClass::dosome() {
...
}
or this:
static std::string MyClass::dosome() {
...
}
I guess I should not repeat the static keyword... is it correct?
C++ compiler will not allow this:
static std::string MyClass::dosome() {
...
}
since having static
in a function definition means something completely different - static
linkage (meaning the function can only be called from the same translation unit).
Having static
in a member function declaration is enough.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With