संभव डुप्लिकेट:
Why would you ever want to allocate memory on the heap rather than the stack?सी ++ सूचक वस्तुओं बनाम गैर सूचक ऑब्जेक्ट्स
Test2 *t2 = new Test2();
t2->test();
Test2 t3;
t3.test();
मैं क्यों प्रकार Test2 का एक सूचक वस्तु बनाने के लिए चाहेगा? टेस्ट 2 का न केवल सूचक संस्करण क्यों न करें? मैं पॉइंटर ऑब्जेक्ट्स क्यों करना चाहूंगा?
यहाँमिले जवाब:
- Why would you ever want to allocate memory on the heap rather than the stack?
- When is it best to use a stack instead of a heap and vice versa?
- When to use "new" and when not to in C++?
- When should I use the new keyword in C++?
- Proper stack and heap usage in C++
- Stack, Static and Heap in C++
कई डुप्लिकेट, जिनमें से पहला ( फिरास असद उत्तर से) http://stackoverflow.com/questions/1549945/why-would-you-ever-want-to-allocate-memory-on-the-heap -rather-than-the-stack –
मुझे अब एहसास है। हालांकि सवाल पूछना कठिन हिस्सा था। अब मुझे लगता है कि मुझे यह मिल रहा है ...: डी –