[ACCEPTED]-If I use explicit constructor, do I need to put the keyword in both .h and .cpp files?-explicit-constructor

Accepted answer
Score: 27

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

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

for the following 1 code:

class foo {
    explicit foo(int);

explicit foo::foo(int) {}
Score: 0

Re the followup question (which you really 5 should have submitted as a separate question), the 4 initialization list goes with the constructor's 3 implementation (its function body), which 2 might be in either the header or the cpp 1 file.

More Related questions