2016-10-31 9 views
11

माइक्रोसॉफ्ट विजुअल सी ++ 2013 (12.0) का उपयोग करते हुए, मुझे एक विविध टेम्पलेट में एक कन्स्ट्रक्टर में लैम्ब्डा का उपयोग करते समय संकलन-समय त्रुटियों का सामना करना पड़ रहा है। जैसा कि नीचे दिखाया गया है, मैंने इसे उबालने में कामयाब रहा है (error टिप्पणियों के साथ लाइनें देखें)। यह 12.0 में एक बग प्रतीत होता है जो 14.0 में मौजूद नहीं है। मैंने अन्य संस्करणों की कोशिश नहीं की है। क्या इस बग पर कोई दस्तावेज है, शायद रिलीज नोट के रूप में जो इस बग के अंतर्गत स्थितियों को स्पष्ट करता है और कौन सा कहता है कि इसे स्पष्ट रूप से तय किया गया है?वैरिएडिक टेम्पलेट्स में लैम्ब्डा

#include <functional> 

// a simple method that can take a lambda 
void MyFunction(const std::function<void()>& f) {} 

// a simple class that can take a lambda 
class MyClass 
{ 
public: 
    MyClass(const std::function<void()>& f) {} 
}; 

// non-templated test 
void test1() 
{ 
    MyFunction([] {}); // OK 
    MyClass([] {}); // OK 
    MyClass o([] {}); // OK 
} 

// non-variadic template test 
template<typename T> 
void test2() 
{ 
    MyFunction([] {}); // OK 
    MyClass([] {}); // OK 
    MyClass o([] {}); // OK 
} 

// variadic template test 
template<typename... T> 
void test3() 
{ 
    MyFunction([] {}); // OK 
    MyClass([] {}); // OK 
    MyClass a([] {}); // error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 
         // error C2440: 'initializing' : cannot convert from 'test3::<lambda_12595f14a5437138aca1906ad0f32cb0>' to 'int' 

    MyClass b(([] {})); // putting the lambda in an extra() seems to fix the problem 
} 

// a function using the templates above must be present 
int main() 
{ 
    test1(); 
    test2<int>(); 
    test3<int, int, int>(); 
    return 1; 
} 
+2

मैंने अभी जोड़ा # # शामिल 'और इसे संकलित किया। मैंने माइक्रोसॉफ्ट विजुअल स्टूडियो कम्युनिटी 2015 संस्करण 14.0.25431.01 अद्यतन 3 – wally

+0

अजीब। मेरे कोड में (#'शामिल है (कॉपी-पेस्ट में शामिल करना भूल गया), लेकिन यह अभी भी मेरे लिए शिकायत करता है। –

+1

जैसा कि जीसीसी और क्लैंग कोड स्वीकार करते हैं ([डेमो] (http://coliru.stacked-crooked.com/a/86fa0b4c990af350))। मैं msvc बग (आपके टेम्पलेट और विविध टेम्पलेट परीक्षण के साथ और भी अधिक) कहूंगा। – Jarod42

उत्तर

-1

आज के रूप में (CppCoreGuidelines के अनुसार), तो आपको {} कोष्ठक प्रारंभकर्ता उपयोग करना चाहिए। क्या तुमने कोशिश की?

MyClass a{[] {}}; 
संबंधित मुद्दे