The code: class foo { public: template<typename T> foo(int i) : j(i) {} template<typename T> void bar(int i) { j = i; } template<typename T> static void baz(int i) {} int j; }; int main() { foo::baz<bool>(3); foo* p; p->bar<bool>(3); new foo<bool>(3); return 0; }
gets you: ~/ootbc/chips$ g++ foo.cc foo.cc: In function âint main()â: foo.cc:8: error: âfooâ is not a template foo.cc:8: error: no matching function for call to âfoo::foo(int)â foo.cc:1: note: candidates are: foo::foo(const foo&) The constructor was declared as a template, and declaring other functions works OK. I can believe that parsing a templated constructor for a templated class is tough and so declaring templated constructors may be illegal. But if it is illegal to have templated constructors then the error should be flagged at the attempted declaration of one, rather than this peculiar message at the invocation site. But it looks to me like the parser hit the "<" in "foo<", saw that foo was not a template, and gave up before looking to see that the foo constructor *was* a template. -- Summary: Fails to accept templated constructor Product: gcc Version: 4.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: igodard at pacbell dot net http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29008