hello , i have a problem on default template argument , for statement "SMART<B> b(a) ;" the good constructor is not in constructor choice for G++ . thanks for help template < typename T > class SMART { T * data ; public : T * Get() {return(data); } ; SMART( T* value ) : data(value) {} ; SMART(SMART<T> & value) : data(value.Get()) {} ; template < typename X , typename X2 = typename X :: T > X2 * CastUp() {return(dynamic_cast<X2>(data)); } ; template < typename X , typename XT2 = T , typename X2 = typename XT2 :: X > SMART(SMART<X2> & value) : data(value.CastUp()) {} ; ~SMART() {} ; } ; class A { public : A() {} ; ~A() {} ; } ; class B : virtual public A { public : B() {} ; ~B() {} ; } ; int method() {SMART<A> a(); SMART<B> b(a) ; } ; cat configure.shl #!/bin/sh export GCC_DIR=`pwd` echo GCC_DIR ./configure --prefix=$GCC_DIR --exec-prefix=$GCC_DIR --libdir=$GCC_DIR/lib --disable-multilib --enable-checking=release --with-tune=generic --enable-mpfr --enable-libstdcxx-debug --enable-clocale=gnu --enable-nls --enable-threads=posix --without-included-gettext --with-system-zlib --enable-linker-build-id --enable-multiarch make make install gcc-4.5-20091126/bin/g++ -std=c++0x -c main.cc main.cc: In function ‘int method()’: main.cc:43:13: erreur: no matching function for call to ‘SMART<B>::SMART(SMART<A> (&)())’ main.cc:11:1: note: candidats sont: SMART<T>::SMART(SMART<T>&) [with T = B] main.cc:9:1: note: SMART<T>::SMART(T*) [with T = B] gcc-4.5-20091126/bin/g++ -v -save-temps -std=c++0x -c main.cc Utilisation des specs internes. COLLECT_GCC=gcc-4.5-20091126/bin/g++ COLLECT_LTO_WRAPPER=/home/admin/webTmp/gcc/gcc-4.5-20091126/libexec/gcc/x86_64-unknown-linux-gnu/4.5.0/lto-wrapper Target: x86_64-unknown-linux-gnu Configuré avec: ./configure --prefix=/home/admin/webTmp/gcc/gcc-4.5-20091126 --exec-prefix=/home/admin/webTmp/gcc/gcc-4.5-20091126 --libdir=/home/admin/webTmp/gcc/gcc-4.5-20091126/lib --disable-multilib --enable-checking=release --with-tune=generic --enable-mpfr --enable-libstdcxx-debug --enable-clocale=gnu --enable-nls --enable-threads=posix --without-included-gettext --with-system-zlib --enable-linker-build-id --enable-multiarch Modèle de thread: posix gcc version 4.5.0 20091126 (experimental) (GCC) COLLECT_GCC_OPTIONS='-v' '-save-temps' '-std=c++0x' '-c' '-shared-libgcc' '-mtune=generic' /home/admin/webTmp/gcc/gcc-4.5-20091126/libexec/gcc/x86_64-unknown-linux-gnu/4.5.0/cc1plus -E -quiet -v -D_GNU_SOURCE main.cc -mtune=generic -std=c++0x -fpch-preprocess -o main.ii le répertoire « /home/admin/webTmp/gcc/gcc-4.5-20091126/lib/gcc/x86_64-unknown-linux-gnu/4.5.0/../../../../x86_64-unknown-linux-gnu/include » est ignoré car inexistant la recherche pour #include "..." débute ici : la recherche pour #include <...> débute ici: /home/admin/webTmp/gcc/gcc-4.5-20091126/lib/gcc/x86_64-unknown-linux-gnu/4.5.0/../../../../include/c++/4.5.0 /home/admin/webTmp/gcc/gcc-4.5-20091126/lib/gcc/x86_64-unknown-linux-gnu/4.5.0/../../../../include/c++/4.5.0/x86_64-unknown-linux-gnu /home/admin/webTmp/gcc/gcc-4.5-20091126/lib/gcc/x86_64-unknown-linux-gnu/4.5.0/../../../../include/c++/4.5.0/backward /usr/local/include /home/admin/webTmp/gcc/gcc-4.5-20091126/include /home/admin/webTmp/gcc/gcc-4.5-20091126/lib/gcc/x86_64-unknown-linux-gnu/4.5.0/include /home/admin/webTmp/gcc/gcc-4.5-20091126/lib/gcc/x86_64-unknown-linux-gnu/4.5.0/include-fixed /usr/include Fin de la liste de recherche. COLLECT_GCC_OPTIONS='-v' '-save-temps' '-std=c++0x' '-c' '-shared-libgcc' '-mtune=generic' /home/admin/webTmp/gcc/gcc-4.5-20091126/libexec/gcc/x86_64-unknown-linux-gnu/4.5.0/cc1plus -fpreprocessed main.ii -quiet -dumpbase main.cc -mtune=generic -auxbase main -std=c++0x -version -o main.s GNU C++ (GCC) version 4.5.0 20091126 (experimental) (x86_64-unknown-linux-gnu) compiled by GNU C version 4.5.0 20091126 (experimental), GMP version 4.3.1, MPFR version 2.4.1-p2 heuristiques GGC: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 GNU C++ (GCC) version 4.5.0 20091126 (experimental) (x86_64-unknown-linux-gnu) compiled by GNU C version 4.5.0 20091126 (experimental), GMP version 4.3.1, MPFR version 2.4.1-p2 heuristiques GGC: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: 55f055424d661ccac322b63c97c280de main.cc: In function ‘int method()’: main.cc:43:13: erreur: no matching function for call to ‘SMART<B>::SMART(SMART<A> (&)())’ main.cc:11:1: note: candidats sont: SMART<T>::SMART(SMART<T>&) [with T = B] main.cc:9:1: note: SMART<T>::SMART(T*) [with T = B]
template < typename X , typename X2 = typename X :: T > X * CastUp() {return(dynamic_cast<X2>(data)); } ;
SMART<A> a(); This does not declare an object of type SMART<A>, it declares a function called 'a' which returns SMART<A> You need to change that to: SMART<A> a; or SMART<A> a = SMART<A>();
Subject: Re: derived template default argument redi at gcc dot gnu dot org wrote: > ------- Comment #2 from redi at gcc dot gnu dot org 2009-12-04 09:48 ------- > SMART<A> a(); > > This does not declare an object of type SMART<A>, it declares a function called > 'a' which returns SMART<A> > > You need to change that to: > > SMART<A> a; > > or > > SMART<A> a = SMART<A>(); > > > the pb is on line : template < typename X , typename XT2 =T , typename X2 = typename XT2 :: X > SMART(SMART<X> & value) : data(value.CastUp) {} ; if i replace the line by > template < typename XT2 = T , typename X2 = typename XT2 :: X > > SMART(SMART<X2> & value) : data(value.CastUp()) {} ; the constructor is find but i want an unherited constraint on X => X2 is T::X sh-3.2$ gcc-4.5-20091126/bin/g++ -std=c++0x -c main.cc main.cc: In constructor ‘SMART<T>::SMART(SMART<X2>&) [with XT2 = B, X2 = A, T = B]’: main.cc:45:13: instantiated from here main.cc:17:118: erreur: no matching function for call to ‘SMART<A>::CastUp()’
(In reply to comment #3) > the pb is on line : > template < typename X , typename XT2 =T , typename X2 = typename XT2 :: > X > SMART(SMART<X> & value) : data(value.CastUp) {} ; I don't understand, that line did not appear in your original report. The error you originally posted is caused by the problem I pointed out. > if i replace the line by > > template < typename XT2 = T , typename X2 = typename XT2 :: X > > > SMART(SMART<X2> & value) : data(value.CastUp()) {} ; > the constructor is find but i want an unherited constraint on X => X2 is > T::X I have no idea what an unherited constraint is. > sh-3.2$ gcc-4.5-20091126/bin/g++ -std=c++0x -c main.cc > main.cc: In constructor ‘SMART<T>::SMART(SMART<X2>&) [with XT2 = B, X2 = > A, T = B]’: > main.cc:45:13: instantiated from here > main.cc:17:118: erreur: no matching function for call to > ‘SMART<A>::CastUp()’ CastUp is a template function but the template parameters cannot be deduced, so you need to say value.CastUp<foo>() for some type "foo" The bug is in your code, not GCC.
the pb is on line : template < typename X , typename XT2 =T , typename X2 = typename XT2 :: X > SMART(SMART<X> & value) : data(value.CastUp) {} ; if i replace the line by > template < typename XT2 = T , typename X2 = typename XT2 :: X > > SMART(SMART<X2> & value) : data(value.CastUp()) {} ; the constructor is find but i want an unherited constraint on X => X2 is T::X sh-3.2$ gcc-4.5-20091126/bin/g++ -std=c++0x -c main.cc main.cc: In constructor ‘SMART<T>::SMART(SMART<X2>&) [with XT2 = B, X2 = A, T = B]’: main.cc:45:13: instantiated from here main.cc:17:118: erreur: no matching function for call to ‘SMART<A>::CastUp()’
i want a constructor on template class SMART<T> with reference parameter on SMART<X> & value with the constraint of T on SMART instanciation is T is unherited of X class A { } ; class B : virtual public A { } ; where T is B and X is A thanks
template < typename X , typename XT2 =T , typename X2 = typename XT2 :: X > SMART(SMART<X> & value) : data(value.CastUp) {} ; The code to do the constructor
.
*** Bug 42296 has been marked as a duplicate of this bug. ***