मैं निम्नलिखित कोडअंक
#include <iostream>
#include <array>
class testClass
{
std::array<int, 2> testArray;
public:
testClass();
void func() const;
};
testClass::testClass() : testArray({{1, 2}})
{
}
void testClass::func() const
{
for (int i = 0; i < 2; ++i)
std::cout << testArray.at(i) << '\n' << testArray[i] << '\n';
}
int main()
{
testClass test;
test.func();
}
साथ अजीब व्यवहार सीमा एक सदस्य एसटीडी जाँच :: MinGW (जीसीसी 4.7.0) के साथ सरणी हो रही है के रूप में यह केवल ऊपर फसलों जब -O
साथ संकलित, मैं व्यक्तिगत झंडे -O
रूप से सक्षम करने की कोशिश की, लेकिन यह किसी भी आगे को कम नहीं कर सका आउटपुट
0
1
0
2
त्रुटि अनुकूलन से संबंधित प्रतीत हो रहा है है। फ़ंक्शन गैर-कॉन्स बनाना भी समस्या को हल करता है। क्या यह एक बग हो सकता है या क्या मुझे कुछ याद आ रहा है?
* संपादित
यह संकुचित नीचे, .at()
#include <iostream>
#include <array>
int main()
{
std::array<int, 2> const testArray = {1, 2};
for (int i = 0; i < 2; ++i)
std::cout << testArray.at(i) << '\n' << testArray[i] << '\n';
}
एक ही उत्पादन का const
संस्करण में एक बग की तरह दिखता है ऊपर के रूप में -std=c++11 -O
Windows XP SP3 और विंडोज 7 पर MinGW 4.7.0 उपयोग करने के साथ संकलित SP1।
* संपादित 2
एक ही उत्पादन फिर से
#include <iostream>
#include <array>
int main()
{
typedef std::array<int, 2> Tarray;
Tarray test = {1, 2};
for (int i = 0; i < 2; ++i)
std::cout << const_cast<Tarray const*>(&test)->at(i) << '\n' << test.at(i) << '\n';
}
http://liveworkspace.org/code/b0d5b3c7398f7e1a2e36838f23fc943c अच्छी तरह से काम करता है। – ForEveR
यह निश्चित रूप से मेरे लिए एक बग की तरह दिखता है। –
यह मेरे लिए [एक अलग आउटपुट] (http://ideone.com/ZhIsS) बनाता है ... – dasblinkenlight