---Code--- 1 #include <iostream> 2 using namespace std; 3 class tclass { 4 public: 5 tclass(); 6 tclass(int); 7 }; 8 tclass::tclass(int j) 9 { 10 cout << j << endl; 11 } 12 tclass::tclass() 13 { 14 int i ; 15 i = 90; *16 tclass::tclass(i); 17 } 18 int main() 19 { 20 tclass t; 21 }
---Compile--- g++ -o tclass tclass.C ---Error Info--- tclass.C: In constructor `tclass::tclass()': tclass.C:16: conflicting types for `tclass i' tclass.C:14: previous declaration as `int i' ---Description--- If you change line 16 to cast explicitly the type of i: tclass::tclass((int)i); Then there is no problem compiling and linking it. I think g++, inside of constructor, always assumes implicitly a constructor tclass(tclass&) and doesn't interpret other constructors with one input parameter correctly. Should be a easy fix! I tried to compile the original code on VC++ 7.1, there is no problem, which confirms that this might be a bug in g++. -- Summary: g++ compile error in calling another constructor inside a constructor Product: gcc Version: 3.3.3 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: ian dot yanliu at gmail dot com GCC host triplet: RedHat Linux 9 i686; Fedora Core 2 i686; SUSE Linux 8.1 IA-64 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26078