Can anyone explain what is wrong with this code? This is a simplification of a problem I isolated in another class. I am using Microsoft Visual C++ in Visual Studio .NET 2003 but using unmanaged code here.
Code:
class c
{
public:
c () {pa = new int [2];}
int f ()
{
pa [0] = 1;
pa [1] = 1;
return 0; // breakpoint here
}
private:
int* pa;
};
int main ()
{
c* pc = new c;
pc -> f();
return 0;
}
Querying the contents of pa at the breakpoint gives pa[0] == 1 but pa[1] == 0. Using numbers other than 1 yields the right result for pa[0] only, and if pa is extended beyond 2 parts it again only works for pa[0]. Help!!!