Click here to Skip to main content
15,887,930 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to use storedList in a loop, for brandList having two values like (Id, text) and I want to store this in the result, I tried this way, I don't know what to do. Please help me, guys.

C++
String *Util::Brands( ) __gc[]
{
    String *result __gc[];
    result = 0;
    SortedList  *brandList = 0;

    if (brandList == 0)
    {
        brandList = BrandCodes();            
    }       

    for (int i =0; i<= brandList->Count; i++)
    {
        result = new String * __gc[2];
        //result[0] = brandList[i]
        //result[1] = brandList[i]
    }

    return result;
}


What I have tried:

for (int i =0; i<= brandList->Count; i++)
    {
        result = new String * __gc[2];
        //result[0] = brandList[i]
        //result[1] = brandList[i]
    }
Posted
Updated 7-Oct-17 9:30am
v3
Comments
Patrice T 5-Oct-17 15:47pm    
Why do you post a question with same code more than once?
How to use list array in C++[^]
Note: this question is as confuse as the first one.
you need to explain clearly what is your problem.

1 solution

This might not be a solution since it is not clear, what you want to accomplish, please provide an example of "If brandList contains a,b,c, then result should look like x,y,z"

But there are several obvious issues already, maybe this gives you a few hints how to proceed:

Your index i is exceeding the bounds of the brandList array in the last loop. Fix: use < instead of <=:
for (int i =0; i < brandList->Count; i++)
    {
        result = new String * __gc[2];
        //result[0] = brandList[i]
        //result[1] = brandList[i]
    }

Another problem is that in every loop you discard the previous result:
for (int i =0; i < brandList->Count; i++)
    {
        result = new String * __gc[2]; // This throws away the previous content
                                       // of result and allocates a new one.
        result[0] = brandList[i];
        result[1] = brandList[i];
    }
    // now result[0] and [1] contains brandList[brandList.Count-1] only
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900