Long time reader first time poster. Searching for this is very obscure so I couldn't find anything.
Anywho, if I declare a struct inside of a class. Then I have a class method that creates instances of said struct, what is the lifespan of the created struct instance?
For instance in my header:
class test_class
{
Public:
void test_function(int, string);
private:
struct test_struct
{
int foo;
string bar;
};
test_struct * storage;
}
Then in test_class.cpp
void test_function(int num, string name)
{
test_struct t1;
t1.foo = num;
t1.bar = name;
storage = new test_struct [<some_size>];
storage[<some_element>] = t1;
}
So, I make an instance of my test_class and call the test_function. t1 is created and then stored successfully in the hypothetical array, but does it stay saved in the array? Or does it get deleted when the function exits because the scope shifts? Does t1 become a member variable of the class? Would I need t1 to be a pointer to a test_struct and have an array of test_struct pointers?
Thank you in advance for the help.