Boost logo

Boost Users :

Subject: Re: [Boost-users] Can not compile a program that uses typeof package by gcc?
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2008-10-20 12:38:56


Peng Yu wrote:
> In instantiation of 'A::multiply_traits<A::X<int>, int>::nested':
> instantiated from 'A::multiply_traits<A::X<int>, int>'
> instantiated from here
> error: no match for 'operator*' in 'A::make [with T =
> A::X<int>]() * A::make [with T = int]()'
> In function 'int main()':
> error: no match for 'operator*' in 'x * 3'
> error: no match for 'operator*' in 'A::X<int>() * 0'
> error: no match for 'operator*' in 'y * 5'
> make: *** [main-g.o] Error 1
> template<class T1, class T2>
> struct multiply_traits {
> BOOST_TYPEOF_NESTED_TYPEDEF_TPL(nested, make<T1>() * make<T2>())
> typedef typename nested::type type;
> };
> template <typename T1, typename T2>
> typename multiply_traits<X<T1>, T2>::result_type operator*(const
> X<T1> &x, const T2 &t) {
> return X<T1>(x.the_t() * t);
> }
> }

Note that the operator* deduces it's return type from multiply_traits,
and multiply_traits in turn uses the result of operator*.
You need to either specialize multiply_traits for X. (The specialization
you #if'ed out should work fine). Or you can change

template<class T1, class T2>
X<T1> operator*(const X<T1> &x, const T2 &t);

Also, I made a mistake, multiply_traits should say
typedef typedef nested::type result_type; instead
of typedef ... type;.

In Christ,
Steven Watanabe

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at