how to declare trailing return type 's prototype?

All I can do now is to put function definition before main() function. I don't know how to declare trailing return type's prototype. Anyone knows?

1
2
3
4
5
template <class T, class D>
auto calculate(T a, D b) -> decltype(a*b)
{
return a*b;
}

Following the code above, how to declare it's prototype or I can just put it before main()?
a template function ususally has no prototype because it's evaluated when it's used.

Apart from that a prototype must match the implementation. I.e. the prototype looks like the function definition just without the body
> Following the code above, how to declare it's prototype

1
2
template <class T, class D> 
auto calculate(T a, D b) -> decltype(a*b) ;


Try this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>

template < class T, class D >
auto calculate( T a, D b ) -> decltype(a*b) ;

template < class T, class D, class E >
auto calculate( T a, D b, E c ) -> decltype( calculate( calculate(a,b), c ) ) ;

int main()
{
    std::cout << calculate( 22, 78.3, 52UL ) << '\n' ;
}

template < class T, class D, class E >
auto calculate( T a, D b, E c ) -> decltype( calculate( calculate(a,b), c ) )
{ return calculate( calculate(a,b), c ) ; }

template < class T, class D >
auto calculate( T a, D b ) -> decltype(a*b) { return a * b ; }
Topic archived. No new replies allowed.