Hi @June Lin ,
I suggest you describe the problem you're having in detail.
I modified your code and now the program runs without any errors and warnings. You could also find that the list has been assigned a value through the for loop.
Is this the result you want?
#include<iostream>
struct DataInformation
{
char* Name;
int Number;
};
DataInformation* data;
DataInformation* GetDataList()
{
int count = 3;
data = new DataInformation[count];
data[0].Name = (char*)"first";
data[0].Number = 1;
data[1].Name = (char*)"second";
data[1].Number = 2;
return data;
}
int main(int argc, char const* argv[])
{
GetDataList();
DataInformation* list = data;
for (int i = 0; i < 2; i++)
{
std::cout << "function: " << list[i].Name << std::endl;
}
free(list);
return 0;
}
Best regards,
Elya
If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.