Halihow! *$ g++ -v *Using built-in specs. Target: x86_64-linux-gnuConfigured with: ../src/configure -v --enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --program-suffix=-4.1 --enable-__cxa_atexit --enable-clocale=gnu --enable-libstdcxx-debug --enable-mpfr --enable-checking=release x86_64-linux-gnu
Thread model: posix gcc version 4.1.2 20061115 (prerelease) (Debian 4.1.1-21) *template* <*typename* T = double> *class* Vector { // ... }; *template* <*typename* T> *const* Vector<T> *operator**(*const* Vector<T>& v, double l) { *return* Vector<T>(v) *= l; } //-------------------------------------- // *"A" valtozat:* //-------------------------------------- int *main*(){ ... // Vector<double> *v4*(v1 * 10);*return* 0;
} g++ -W -Wall -O2 -Wno-non-template-friend -Wold-style-cast -Wsign-promo -Wstrict-null-sentinel -c -o main.o main.cpp g++ main.o -o main main.o: In function `main': main.cpp:(.text+0x324): *undefined reference to `operator*(Vector<double> const&, double)'* collect2: ld returned 1 exit status make: *** [main] Error 1 Nyomjon meg egy billentyűt... //-------------------------------------- // *"B" valtozat:* //-------------------------------------- int *main*(){ ... Vector<double> *v4*(*operator**<double>(v1,10));*return* 0;
} g++ -W -Wall -O2 -Wno-non-template-friend -Wold-style-cast -Wsign-promo -Wstrict-null-sentinel -c -o main.o main.cpp g++ main.o -o main Nyomjon meg egy billentyűt... Tehát:Ha explicit megmondom neki, hogy egy operator*<double>()-t legyen szives használni akkor minden sima, de magától nem jönne rá. Ez viszont éppen megöli a lényeget, mert akkor írhatnék egy statikus metódust is és mondhatnám azt, hogy v4=Vector::Mul(v1,10);.
Tud valaki valami szépet mondani? Kösz: Nil.