Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Cast ArrayList mc++

Posted on 2005-04-09
3
Medium Priority
?
425 Views
Last Modified: 2008-01-09
Hi,
I get the following conversion errors when using ArrayList

ArrayList szContents;
...

...
int a = int (szContents->get_Item);

error c2440: 'type cast' : cannot convert deom 'System::Object:: __gc*' to 'int'

how do I solve - thanks
0
Comment
Question by:dm14011
  • 2
3 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 13743855
int a = (int)szContents->get_Item(index);

index is item index in the list.
0
 

Author Comment

by:dm14011
ID: 13743971
sorry, thats what I've done, just didnt write it properly. I still get the error.
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 2000 total points
ID: 13746107
#include "stdafx.h"

#using <mscorlib.dll>

using namespace System;
using namespace System::Collections;

int _tmain()
{
    ArrayList* szContents = new ArrayList();

    szContents->Add(__box(1));
    szContents->Add(__box(2));
    szContents->Add(__box(3));

    for ( int i = 0; i < szContents->get_Count(); i++ )
    {
        int n = *dynamic_cast<__box int*>(szContents->get_Item(i));

        Console::WriteLine(n.ToString());
    }

    return 0;
}
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Suggested Courses

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question