[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 673
  • Last Modified:

.NET "ArrayList" equivalent in unmanaged C++

Hi,

I'm trying to find out if there is a way to implement an ArrayList class in unmanaged c++ (Linux) , that has the same methods, add, insert, remove, contains, count, etc.

I've been using C# on Windows for a 3D project i am working on, but i want it to be cross-platform, and currently there are no production ready .NET engines that work with Mono and also support OpenGL. There are a few C++ engines that are cross-platform and i am contemplating re-learning C++ (havnt used it in several years since i started programming again). But i've already gotten use to the nice features of the .net framework. it would be easier if/when mono supports managed c++, but who knows when that will be ready.

Thanks in advance for any help.

PS, please provide detailed examples, as i am still re-learning C++. thanks.
0
RepriseMIS
Asked:
RepriseMIS
1 Solution
 
mrblueCommented:
Heve you considered usage of STL (Standard Template Library) ?
It has many container classes like map, vector, queue, ..., algoritms that operates on these containers & so called iterators that allow algoritms to access data in containers.
0
 
jkrCommented:
In fact, if you compare http://msdn2.microsoft.com/en-us/library/system.collections.arraylist.aspx to http://www.sgi.com/tech/stl/List.html or http://www.sgi.com/tech/stl/Vector.html you'll find a lot of similarities. The code using ArrayList can be rewritten to be

#include <iostream>
#include <list>
#include <string>
using namespace std;

void PrintValues(list<string>& rlst);

void main () {

    list<string> lst;

    lst.push_back("Hello");
    lst.push_back("World");
    lst.push_back("!");

    cout << "lst" << endl;
    cout << "Count :" lst.size() << endl;
}

void PrintValues(list<string>& rlst) {

    list<string>::iterator i;

    for (i = rlst.begin(); i != rlst.end(); ++i) {

        cout << *i << endl;
    }
}

or

#include <iostream>
#include <vector>
#include <string>
using namespace std;

void PrintValues(vector<string>& rlst);

void main () {

    vector<string> vec;

    vec.push_back("Hello");
    vec.push_back("World");
    vec.push_back("!");

    cout << "vec" << endl;
    cout << "Count :" lst.size() << endl;
}

void PrintValues(vector<string>& rvec) {

    vector<string>::iterator i;

    for (i = rvec.begin(); i != rvec.end(); ++i) {

        cout << *i << endl;
    }
}

If you feel like staying with MS' libraries, there is also 'CArray' and 'CList', see e.g. http://www.codeproject.com/cpp/#Collections
0
 
AlexFMCommented:
You can write wrapper using STL list<void*> to make emulation of ArrayList.
To emulate .NET 2.0 List<> which continues ArrayList with generics, use template class with list<T>.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now