Re: C++: Problem with overloading a constructor when splitting a
> > > On Sun, 18 Nov 2001, Shaul Karl wrote: > > > > you have put an inline function inside a '.cc' file. since it is inline, > > > it will NOT be included in the object file 'base.cc', and thus, during > > > link, there base constructor will be undefined. this is your bug - not > > > g++'s. > > > > > > fixes: > > > > > > 1. move the inline function into the header file. > > > 2. make the function not 'inline'. > > > > Are there no other options? In particular, one that is both inline and > > with split files? (inline for speed and splitting the src for > > readability) > > by definition - no. you split source - you can't do inline. inline works > if you put it in the header file. that's the idea of inline - copying the > code to all other sources, rather then having a real function in the > resulting object file. > This may seem an ugly feature of C++, but in fact it is better than the C counterpart - macros. In fact, writing the implementation of inline functions in header file is a beautiful gem, comparing to writing the implemetation of calss templates in header files. Yuck. Dan. = To unsubscribe, send mail to [EMAIL PROTECTED] with the word "unsubscribe" in the message body, e.g., run the command echo unsubscribe | mail [EMAIL PROTECTED]
Re: C++: Problem with overloading a constructor when splitting a
On Sun, 18 Nov 2001, Dan Kenigsberg wrote: > This may seem an ugly feature of C++, but in fact it is better than the C > counterpart - macros. In fact, writing the implementation of inline functions > in header file is a beautiful gem, comparing to writing the implemetation of > calss templates in header files. Yuck. actually, writing the implementation of class templates in header files is *not* a language feature, it's a limitation of current (?) compiler technology, which can not handle templates being split up in different compilation units. [ i would supply more details, but couldnt find any references on google. if anyone can shed more light, please do. ] -- mulix http://www.pointer.co.il/~mulix/ http://syscalltrack.sf.net/ = To unsubscribe, send mail to [EMAIL PROTECTED] with the word "unsubscribe" in the message body, e.g., run the command echo unsubscribe | mail [EMAIL PROTECTED]
Re: C++: Problem with overloading a constructor when splitting a
Dan Kenigsberg <[EMAIL PROTECTED]> writes: > This may seem an ugly feature of C++, but in fact it is better than > the C counterpart - macros. Inlined functions are supposed to be a standard C feature in C99. GCC has had them for years. > In fact, writing the implementation of inline functions in header > file is a beautiful gem, comparing to writing the implemetation of > calss templates in header files. Yuck. Well, don't blame C for that. Yuck, indeed - breaks modularizations etc. -- Oleg Goldshmidt | [EMAIL PROTECTED] "If it ain't broken, it has not got enough features yet." = To unsubscribe, send mail to [EMAIL PROTECTED] with the word "unsubscribe" in the message body, e.g., run the command echo unsubscribe | mail [EMAIL PROTECTED]
Re: C++: Problem with overloading a constructor when splitting a
See discussion on export keyword, p. 205 in The C++ Programming Language (3rd edn.), Stroustrup. It should do the job, but I don't know in GNU c++ implements it. mulix wrote: > On Sun, 18 Nov 2001, Dan Kenigsberg wrote: > > >>This may seem an ugly feature of C++, but in fact it is better than the C >>counterpart - macros. In fact, writing the implementation of inline functions >>in header file is a beautiful gem, comparing to writing the implemetation of >>calss templates in header files. Yuck. >> > > actually, writing the implementation of class templates in header files > is *not* a language feature, it's a limitation of current (?) compiler > technology, which can not handle templates being split up in different > compilation units. > > [ i would supply more details, but couldnt find any references on > google. if anyone can shed more light, please do. ] > = To unsubscribe, send mail to [EMAIL PROTECTED] with the word "unsubscribe" in the message body, e.g., run the command echo unsubscribe | mail [EMAIL PROTECTED]
Re: C++: Problem with overloading a constructor when splitting a
Daniel Feiglin <[EMAIL PROTECTED]> writes: > See discussion on export keyword, p. 205 in The C++ Programming > Language (3rd edn.), Stroustrup. It should do the job, but I don't > know in GNU c++ implements it. No. You get warning: keyword 'export' not implemented and will be ignored with gcc 2.96. I don't know about gcc 3.* - have not tried it yet. -- Oleg Goldshmidt | [EMAIL PROTECTED] "If it ain't broken, it has not got enough features yet." = To unsubscribe, send mail to [EMAIL PROTECTED] with the word "unsubscribe" in the message body, e.g., run the command echo unsubscribe | mail [EMAIL PROTECTED]
C++: Problem with overloading a constructor when splitting a src file.
Part 1: this works as expected -- [01:27:40 tmp]$ cat main.cc #include #include using namespace std; class base { public: base(); base(string &str); }; class derived : public base { public: derived(string &str) : base(str) {} }; inline base::base() {} inline base::base(string &str) { cout << str << endl; } int main(void) { string str("test succeeded."); derived testingDerived(str); } [01:27:45 tmp]$ g++-3.0 -Wall -o main main.cc main.cc: In function `int main()': main.cc:30: warning: unused variable `derived testingDerived' [01:29:10 tmp]$ Part 2: Why this does not work? --- Next I have tried to split this into 3 files: [01:19:08 tmp]$ more *.h *.cc :: header.h :: #include #include using namespace std; class base { public: base(); base(string &str); }; class derived : public base { public: derived(string &str) : base(str) {} }; :: base.cc :: #include "header.h" inline base::base() {} inline base::base(string &str) { cout << str << endl; } :: main.cc :: #include "header.h" int main(void) { string str("test succeeded."); derived testingDerived(str); } [01:19:40 tmp]$ for f in *.cc; do C="g++-3.0 -Wall -c -o ${f%.*}.o $f"; echo $C;$($C); done; C="g++-3.0 -Wall -o main main.o base.o"; echo $C; $($C); g++-3.0 -Wall -c -o base.o base.cc g++-3.0 -Wall -c -o main.o main.cc main.cc: In function `int main()': main.cc:6: warning: unused variable `derived testingDerived' g++-3.0 -Wall -o main main.o base.o main.o: In function `derived::derived(std::string&)': main.o(.gnu.linkonce.t._ZN7derivedC1ERSs+0x10): undefined reference to `base::base(std::string&)' collect2: ld returned 1 exit status [01:20:53 tmp]$ Why it does not work? Is this reproducible with other distros or g++ versions? [01:20:53 tmp]$ g++-3.0 -v Reading specs from /usr/lib/gcc-lib/i386-linux/3.0.2/specs Configured with: ../src/configure -v --enable-languages=c,c++,java,f77,p roto,objc --prefix=/usr --infodir=/share/info --mandir=/share/man --enable-shared --with-gnu-as --with-gnu-ld --with-system-zlib --enable-long-long --enable-nls --without-included-gettext --disable-checking --enable-threads=posix --enable-java-gc=boehm --with-cpp-install-dir=bin --enable-objc-gc i386-linux Thread model: posix gcc version 3.0.2 20010922 (Debian prerelease) [01:23:23 tmp]$ -- Shaul Karl email: shaulka (replace these parenthesis with @) bezeqint, delete the comma and the white space characters and add .net = To unsubscribe, send mail to [EMAIL PROTECTED] with the word "unsubscribe" in the message body, e.g., run the command echo unsubscribe | mail [EMAIL PROTECTED]
Re: C++: Problem with overloading a constructor when splitting a src file.
you have put an inline function inside a '.cc' file. since it is inline, it will NOT be included in the object file 'base.cc', and thus, during link, there base constructor will be undefined. this is your bug - not g++'s. fixes: 1. move the inline function into the header file. 2. make the function not 'inline'. guy On Sun, 18 Nov 2001, Shaul Karl wrote: > Date: Sun, 18 Nov 2001 01:38:10 +0200 > From: Shaul Karl <[EMAIL PROTECTED]> > To: [EMAIL PROTECTED] > Subject: C++: Problem with overloading a constructor when splitting a > src file. > > Part 1: this works as expected > -- > > [01:27:40 tmp]$ cat main.cc > #include > #include > > using namespace std; > > class base > { > public: > base(); > base(string &str); > }; > > class derived : public base > { > public: > derived(string &str) : base(str) {} > }; > > inline base::base() {} > > inline base::base(string &str) > { > cout << str << endl; > } > > > int main(void) > { > string str("test succeeded."); > derived testingDerived(str); > } > > [01:27:45 tmp]$ g++-3.0 -Wall -o main main.cc > main.cc: In function `int main()': > main.cc:30: warning: unused variable `derived testingDerived' > [01:29:10 tmp]$ > > > > Part 2: Why this does not work? > --- > > Next I have tried to split this into 3 files: > > [01:19:08 tmp]$ more *.h *.cc > :: > header.h > :: > #include > #include > > using namespace std; > > class base > { > public: > base(); > base(string &str); > }; > > class derived : public base > { > public: > derived(string &str) : base(str) {} > }; > :: > base.cc > :: > #include "header.h" > > inline base::base() {} > > inline base::base(string &str) > { > cout << str << endl; > } > :: > main.cc > :: > #include "header.h" > > int main(void) > { > string str("test succeeded."); > derived testingDerived(str); > } > > > [01:19:40 tmp]$ for f in *.cc; do C="g++-3.0 -Wall -c -o ${f%.*}.o $f"; > echo $C;$($C); done; C="g++-3.0 -Wall -o main main.o base.o"; echo $C; > $($C); > g++-3.0 -Wall -c -o base.o base.cc > g++-3.0 -Wall -c -o main.o main.cc > main.cc: In function `int main()': > main.cc:6: warning: unused variable `derived testingDerived' > g++-3.0 -Wall -o main main.o base.o > main.o: In function `derived::derived(std::string&)': > main.o(.gnu.linkonce.t._ZN7derivedC1ERSs+0x10): undefined reference to > `base::base(std::string&)' > collect2: ld returned 1 exit status > [01:20:53 tmp]$ = To unsubscribe, send mail to [EMAIL PROTECTED] with the word "unsubscribe" in the message body, e.g., run the command echo unsubscribe | mail [EMAIL PROTECTED]
Re: C++: Problem with overloading a constructor when splitting a src file.
> > you have put an inline function inside a '.cc' file. since it is inline, > it will NOT be included in the object file 'base.cc', and thus, during > link, there base constructor will be undefined. this is your bug - not > g++'s. > > fixes: > > 1. move the inline function into the header file. > 2. make the function not 'inline'. > > guy > Are there no other options? In particular, one that is both inline and with split files? (inline for speed and splitting the src for readability) > On Sun, 18 Nov 2001, Shaul Karl wrote: > > > Date: Sun, 18 Nov 2001 01:38:10 +0200 > > From: Shaul Karl <[EMAIL PROTECTED]> > > To: [EMAIL PROTECTED] > > Subject: C++: Problem with overloading a constructor when splitting a > > src file. > > > > Part 1: this works as expected > > -- > > > > [01:27:40 tmp]$ cat main.cc > > #include > > #include > > > > using namespace std; > > > > class base > > { > > public: > > base(); > > base(string &str); > > }; > > > > class derived : public base > > { > > public: > > derived(string &str) : base(str) {} > > }; > > > > inline base::base() {} > > > > inline base::base(string &str) > > { > > cout << str << endl; > > } > > > > > > int main(void) > > { > > string str("test succeeded."); > > derived testingDerived(str); > > } > > > > [01:27:45 tmp]$ g++-3.0 -Wall -o main main.cc > > main.cc: In function `int main()': > > main.cc:30: warning: unused variable `derived testingDerived' > > [01:29:10 tmp]$ > > > > > > > > Part 2: Why this does not work? > > --- > > > > Next I have tried to split this into 3 files: > > > > [01:19:08 tmp]$ more *.h *.cc > > :: > > header.h > > :: > > #include > > #include > > > > using namespace std; > > > > class base > > { > > public: > > base(); > > base(string &str); > > }; > > > > class derived : public base > > { > > public: > > derived(string &str) : base(str) {} > > }; > > :: > > base.cc > > :: > > #include "header.h" > > > > inline base::base() {} > > > > inline base::base(string &str) > > { > > cout << str << endl; > > } > > :: > > main.cc > > :: > > #include "header.h" > > > > int main(void) > > { > > string str("test succeeded."); > > derived testingDerived(str); > > } > > > > > > [01:19:40 tmp]$ for f in *.cc; do C="g++-3.0 -Wall -c -o ${f%.*}.o $f"; > > echo $C;$($C); done; C="g++-3.0 -Wall -o main main.o base.o"; echo $C; > > $($C); > > g++-3.0 -Wall -c -o base.o base.cc > > g++-3.0 -Wall -c -o main.o main.cc > > main.cc: In function `int main()': > > main.cc:6: warning: unused variable `derived testingDerived' > > g++-3.0 -Wall -o main main.o base.o > > main.o: In function `derived::derived(std::string&)': > > main.o(.gnu.linkonce.t._ZN7derivedC1ERSs+0x10): undefined reference to > > `base::base(std::string&)' > > collect2: ld returned 1 exit status > > [01:20:53 tmp]$ > -- Shaul Karl email: shaulka (replace these parenthesis with @) bezeqint, delete the comma and the white space characters and add .net = To unsubscribe, send mail to [EMAIL PROTECTED] with the word "unsubscribe" in the message body, e.g., run the command echo unsubscribe | mail [EMAIL PROTECTED]