ArrayList class in Visual C++ .NET 2003

B

bor_kev

Hi,

I'm using Visual C++ .NET 2003 and I want to use the ArrayList class
in order to put managed classes in it.

For instance , i wrote :
(I created an empty .NET project)


#using namespace System::Collections;

__gc class point
{
protected :
int x; inty;

public :
point( int valx, int valy)
{
x=valx;
y=valy;
}

void getx{ return x;}
void gety {return y;}


// no destructor since it's a managed class

};

int main()
{
point pt1(5,2);

ArrayList * pal = new ArrayList(10);

pal->Add(pt1);

return 0;
}

The compiler says that it cannot convert this point class into
Object*.
Then i tried to inherate point from the Object class...in vain.

I also tried pal->Add(__box(pt1));...in vain.

My question is : What should I do to store managed classes into the
ArrayList and work with them?

Sincerely

bor_kev
Posted at: http://www.groupsrv.com
 
C

Carl Daniel [VC++ MVP]

bor_kev said:
Hi,

I'm using Visual C++ .NET 2003 and I want to use the ArrayList class
in order to put managed classes in it.

For instance , i wrote :
(I created an empty .NET project)


#using namespace System::Collections;

__gc class point
{
protected :
int x; inty;

public :
point( int valx, int valy)
{
x=valx;
y=valy;
}

void getx{ return x;}
void gety {return y;}


// no destructor since it's a managed class

};

int main()
{
point pt1(5,2);

point* pt1 = new point(5,2);
ArrayList * pal = new ArrayList(10);

pal->Add(pt1);

return 0;
}

-cd
 

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