As your compiler says:
main.cpp:10:65: error: expected a type, got ‘std::conditional<(sizeof (T) > sizeof (U)), int, float>::type’
There is a typename missing before std::conditional<...
.
Question
I asked a question here, C++ template argument with expression, and got an answer but now I want to move onto something like this:
#include <complex>
#include <type_traits>
using namespace std;
template<class T, class U>
complex< conditional<(sizeof( T ) > sizeof( U )), T, U>::type > my_method(T x, U y) { }
This gives me the errors:
main.cpp:10:65: error: type/value mismatch at argument 1 in template parameter list for ‘template<class _Tp> struct std::complex’
main.cpp:10:65: error: expected a type, got ‘std::conditional<(sizeof (T) > sizeof (U)), int, float>::type’
I have tried adding the key word typename and class before T and U, but that changes the error too:
main.cpp:37:1: error: wrong number of template arguments (1, should be 3)
/usr/include/c++/4.7/type_traits:77:12: error: provided for ‘template<bool <anonymous>, class, class> struct std::conditional’
main.cpp:10:10: error: template argument 1 is invalid
main.cpp:10:1: error: expected unqualified-id at end of input
I am using g++ with -std=c++11 as a compiler option on linux. Is there anyway to do what I am trying to do?
Thanks.
Solution
As your compiler says:
main.cpp:10:65: error: expected a type, got ‘std::conditional<(sizeof (T) > sizeof (U)), int, float>::type’
There is a typename missing before std::conditional<...
.