[ACCEPTED]-If I use explicit constructor, do I need to put the keyword in both .h and .cpp files?-explicit-constructor
Accepted answer
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 {
public:
explicit foo(int);
};
explicit foo::foo(int) {}
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.
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.