Re: A<T> is not derived from B<T>

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 11 March 2011 16:35, SPUeNTRUP - Kai Henningsen wrote:
> ... or more precisely,
> error: type ‘accessor_parameter<T, (sizeof (T) > sizeof (T*))>’ is not derived from type ‘C3Variable<T>’
>
> In this case, I can work around this, but I'd like to understand what
> is going on here. The accessor_parameter is a return type of a method of
> template class C3Variable (an otherwise trivial getter method of an
> instance var of type T). (The main point is to automate the decision of
> transferring a value or a pointer to the value, thus the condition.)
>
> gcc -v:
>
> Using built-in specs.
> Target: x86_64-linux-gnu
> Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.4.4-14ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.4 --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
> Thread model: posix
> gcc version 4.4.5 (Ubuntu/Linaro 4.4.4-14ubuntu5)
>
> Oh, just in case it matters:
>
> template < class C, bool > struct accessor_parameter {
> };
> template <> template < class C > struct accessor_parameter <C, true > {
>    typedef const C & type;
> };
> template <> template < class C > struct accessor_parameter <C, false > {
>    typedef C type;
> };
> #    define accessor_pt(T)  \
>    accessor_parameter < T, (sizeof(T) > sizeof(T *)) >::type
>
> ... and more macros, ending in ACCESSOR_R(name, type) for a getter,
> ACCESSOR_W(name, type) for a setter, and so on. I believe this is the
> first time I tried to use this in a template class, however.

In this case, the error is not very helpful. It means you have a
missing "typename"

template<class T>
struct C3Variable
{
    accessor_pt(T) get();
};

Needs to be changed to

template<class T>
struct C3Variable
{
    typename accessor_pt(T) get();
};

(Or you could put the "typename" in the macro, but then it wouldn't
work in non-templates)



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux