https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67113
Bug ID: 67113 Summary: unintelligent error message "only declarations of constructors can be 'explicit'" in cpp file's constructor define. Product: gcc Version: 4.9.2 Status: UNCONFIRMED Severity: minor Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: robinh3123 at gmail dot com Target Milestone: --- For the following codes (in 3 files): $ cat a.cpp #include "a.h" int A::f() { return n+1; } explicit A::A(int _n) // <=== error at this line { n = _n; } $ cat a.h class A { public: int n; int f(); explicit A(int _n); }; $ cat main.cpp #include <iostream> #include "a.h" // for class A using namespace std; int main() { A a(5); int i = a.f(); cout << i << endl; return 0; } The compiler reports error message: a.cpp:8:21: error: only declarations of constructors can be 'explicit' explicit A::A(int _n) This is misleading, since A::A is really a constructor. The error message should be something similar to: extra explicit before function A::A