C++ – If I use explicit constructor, do I need to put the keyword in both .h and .cpp files

c++explicit-constructor

Actually my question is all in the title.
Anyway:
I have a class and I use explicit constructor:

.h

class MyClass
{
  public:
    explicit MyClass(const string& s): query(s) {}
  private:
   string query;
}

Is it obligatory or not to put explicit keyword in implementation(.cpp) file?

Best Solution

No, it is not. The explicit keyword is only permitted in the header. My gcc says:

test.cpp:6: error: only declarations of constructors can be 'explicit'

for the following code:

class foo {
public:
    explicit foo(int);
};

explicit foo::foo(int) {}