2016-07-16 13 views
5
#include <type_traits> 

template<int n> 
std::enable_if_t<n == 1, int> f() {} 
// OK 

template<int n> 
std::enable_if_t<n > 1, int> g() {} 
// VS2015 : error C2988: unrecognizable template declaration/definition 

int main() 
{} 

मुझे पता है कि संकलक के कारण त्रुटि टेम्पलेट समाप्ति चिह्न के रूप में "से अधिक" साइन '>' लेती है।सी ++ टेम्पलेट्स में तुलनात्मक अभिव्यक्तियों का उपयोग कैसे करें?

मेरा प्रश्न है: ऐसे मामले में, तुलना अभिव्यक्ति कानूनी कैसे बनाएं?

उत्तर

7

कोष्टक में अभिव्यक्ति रखो:

#include <type_traits> 

template<int n> 
std::enable_if_t<(n == 1), int> f() { } 

template<int n> 
std::enable_if_t<(n > 1), int> g() { } 

int main() { } 
संबंधित मुद्दे