B
Bryan
I've been messing around with a C++ application on Xbox, and have been
encountering problems with my objects getting garbage collected when
they go out of scope, but before I'm actually done using them. I'm not
really familiar with how this works in C++, since I first learned C,
then Java, and never really spent a lot of time learning C++ other
than applying Java concepts to C++'s syntax. Here's my problem:
I have a function (doesn't matter if it's a class method or just a
random function) which instantiates an object of the Rect class by
calling its constructor ( Rect asdf = Rect(100, 200, ... ); ) and then
returns a pointer to asdf. However, once the function returns, asdf
gets garbage collected (at least, I'm assuming that's what happens,
since it's the only explanation I can think of for...) and my returned
pointer is useless, and breaks my app if I try to use it. I guess in C
I would have gotten around this by using malloc() to allocate the
memory for asdf, but since I'm using C++ that would cause my
constructor to not get called. There are probably a couple things
about constructors in C++ I don't know that would help out here, so if
anyone can help me out with that or suggest other ideas about how to
fix this problem I'd appreciate it. Thanks in advance.
Bryan
encountering problems with my objects getting garbage collected when
they go out of scope, but before I'm actually done using them. I'm not
really familiar with how this works in C++, since I first learned C,
then Java, and never really spent a lot of time learning C++ other
than applying Java concepts to C++'s syntax. Here's my problem:
I have a function (doesn't matter if it's a class method or just a
random function) which instantiates an object of the Rect class by
calling its constructor ( Rect asdf = Rect(100, 200, ... ); ) and then
returns a pointer to asdf. However, once the function returns, asdf
gets garbage collected (at least, I'm assuming that's what happens,
since it's the only explanation I can think of for...) and my returned
pointer is useless, and breaks my app if I try to use it. I guess in C
I would have gotten around this by using malloc() to allocate the
memory for asdf, but since I'm using C++ that would cause my
constructor to not get called. There are probably a couple things
about constructors in C++ I don't know that would help out here, so if
anyone can help me out with that or suggest other ideas about how to
fix this problem I'd appreciate it. Thanks in advance.
Bryan