मैं Microsoft Visual Studio समुदाय 2019, V16.5.2 का उपयोग कर रहा हूं। मैं सूची आरंभीकरण का परीक्षण करना चाहता हूं
कृपया निम्नलिखित परीक्षण कार्यक्रम देखें:
#include <string>
void foo(std::string str) {}
int main() {
foo( {"str1", "str2"} );
return 0;
}
यह त्रुटि और चेतावनी के बिना संकलित करता है। क्यों?
यह रनटाइम त्रुटि देता है: Expression: Transposed pointer range
क्या कोई समझा सकता है कि यहाँ क्या हो रहा है?
संपादित करें।
मैंने कोड को अलग कर दिया और इसे डिबगर में चला दिया
foo( {"str1", "str2"} );
00F739A8 sub esp,1Ch
00F739AB mov esi,esp
00F739AD mov dword ptr [ebp-0C8h],esp
00F739B3 lea ecx,[ebp-0D1h]
00F739B9 call std::allocator<char>::allocator<char> (0F7136Bh)
00F739BE push eax
00F739BF push offset string "str2" (0F84DB8h)
00F739C4 push offset string "str1" (0F84E2Ch)
00F739C9 mov ecx,esi
00F739CB call std::basic_string<char,std::char_traits<char>,std::allocator<char> >::basic_string<char,std::char_traits<char>,std::allocator<char> ><char const *,0> (0F71569h)
00F739D0 call std::basic_string<char,std::char_traits<char>,std::allocator<char> >::basic_string<char,std::char_traits<char>,std::allocator<char> > (0F71843h)
00F739D5 add esp,1Ch
यह कंस्ट्रक्टर को पहली कॉल पर क्रैश कर देता है?