cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
General C++ Programming
Object creation on stack in loop
Object creation on stack in loop
Apr 29, 2014 at 10:05am UTC
icegood
(63)
have a piece of code
1
2
3
4
5
6
for
(
int
i = 0; i<5; i++) { CMyStackObject sobj;
//
... }
Does standard guarantees that instances of sobj will be different for different i?
Apr 29, 2014 at 10:12am UTC
mutexe
(2372)
they'll be different. each one will 'die' when it goes out of scope at the end of the for loop.
Last edited on
Apr 29, 2014 at 10:15am UTC
Apr 29, 2014 at 10:12am UTC
kbw
(9488)
Yes, the instances will be different. But it's likely that the instances will be instantiated at the same location in memory (i.e. they have the same value for the this pointer).
Apr 29, 2014 at 10:35am UTC
icegood
(63)
OK, thanks. No matter, of course, whether pointer will be on very same place or another. For me critical is to have destructor to be called.
sobj is actually that well known helper object for RAII technology.
Topic archived. No new replies allowed.