मैंने इसे गोगल किया & ने SO पर भी इसी तरह के प्रश्न को खोजने का प्रयास किया लेकिन कुछ भी उपयोगी नहीं मिला। तो, यहां मेरा प्रश्न पोस्ट कर रहा है।स्ट्रिंग के लिए बूल का निहित रूपांतरण क्यों त्रुटि नहीं है?
#include <iostream>
void foo(const std::string &) {}
int main()
{
foo(false);
}
[Warning] converting 'false' to pointer type for argument 1 of 'std::basic_string::basic_string(const _CharT*, const _Alloc&) [with _CharT = char; _Traits = std::char_traits; _Alloc = std::allocator]' [-Wconversion-null]
क्यों सी ++ इस स्पष्ट कलाकारों के बिना अनुमति देता है:
इस कार्यक्रम पर विचार करें? मैं संकलक त्रुटि प्राप्त करने की उम्मीद कर रहा था।
terminate called after throwing an instance of 'std::logic_error'
what(): basic_string::_S_construct null not valid
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
मानक अंतर्निहित रूपांतरण के इस प्रकार के बारे में क्या कहते हैं: कार्यक्रम असामान्य रूप से प्रदर्शित निम्न अपवाद के कारण कार्यावधि में समाप्त हो जाता है?
"इस प्रकार के निहित रूपांतरण के बारे में मानक क्या कहता है?" यह कहता है कि इसकी अनुमति है। – juanchopanza
@juanchopanza: नहीं। ऐसा नहीं है। आपको सी ++ मानक से प्रासंगिक पाठ लिखना होगा। – Destructor
@ डाउनवॉटर: क्यों डाउनवॉट्स? सवाल में क्या गलत है? – Destructor