Adding objects to array in vc++

S

Stefan Soljemo

I trying to add objects to an array without success. The array is declared as
A** arr**. It is allocated with with the new operator. Two instances of the
class A is allready instanciated with the new operator and assigned to the
array with the brackets [] as shown below. The problem is that both elements
in the array is assigned the first obejct Test1.
Note that the main class is managed.
Im using Microsoft Visual Studio 2008.

Thanks on advance!
Stefan

namespace Test {


class A
{
public:

virtual int Funca()
{
int a = 5;
return a;
}
};

public ref class Class2
{
public:
void Test( void)
{
A *Test1;
A *Test2;

Test1 = new A();
Test2 = new A();

A **arr;

arr = new A *[2];
arr[ 0] = Test1;
arr[ 1] = Test2;
}
};
}

Watch 1 window at the end
+ arr[0] 0x055E87F8 Test::A*
+ arr[1] 0x055E87F8 Test::A*
 
M

Mark Salsbery [MVP]

Stefan Soljemo said:
I trying to add objects to an array without success. The array is declared
as
A** arr**. It is allocated with with the new operator. Two instances of
the
class A is allready instanciated with the new operator and assigned to the
array with the brackets [] as shown below. The problem is that both
elements
in the array is assigned the first obejct Test1.
Note that the main class is managed.
Im using Microsoft Visual Studio 2008.



It's a bug.

If you look at the array in a memory window, you'll see the two different
pointers, so at least the compiled code works correctly :).

I'll pass this on to Microsoft.

Mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top