OK to use managed C++ classes in STL collections? 
Author Message
 OK to use managed C++ classes in STL collections?

Suppose a have a managed C++ class named Managed.  Is the following
acceptable?

#include <map>
#include <string>

using namespace std;
map<string, Managed> myManagedMap;
// or alternatively
map<string, * Managed> myManagedPointerMap;

-- Barry



Wed, 05 Oct 2005 02:45:03 GMT  
 OK to use managed C++ classes in STL collections?
Barry,

Quote:
> Suppose a have a managed C++ class named Managed.  Is the following
> acceptable?

> #include <map>
> #include <string>

> using namespace std;
> map<string, Managed> myManagedMap;
> // or alternatively
> map<string, * Managed> myManagedPointerMap;

I don't think so (although I haven't tried it). Unmanaged types (such as
map) can't directly hold of references to managed objects. (and you'd
certainly need to hold __gc pointers, no way you could hold the actual
classes, at least if we're talking __gc classes here).

What is it exactly you're trying to do? Perhaps we can suggest a better
way...
--
Tomas Restrepo



Wed, 05 Oct 2005 03:19:52 GMT  
 OK to use managed C++ classes in STL collections?
Looks like you can't very easily from responses on the following web page:
http://www.dotnet247.com/247reference/msgs/23/118973.aspx

I'll stick with managed collections for managed classes.


Quote:
> Suppose a have a managed C++ class named Managed.  Is the following
> acceptable?

> #include <map>
> #include <string>

> using namespace std;
> map<string, Managed> myManagedMap;
> // or alternatively
> map<string, * Managed> myManagedPointerMap;

> -- Barry



Wed, 05 Oct 2005 03:28:08 GMT  
 OK to use managed C++ classes in STL collections?
Just need to create a collection of managed classes the quickest way I know
how.   I'm new at .NET programming, although I've done a bit of reading on
it and playing around some with C# and VB.NET code.  It looks like I'll
start out with the System.Collections.Hashtable and figure out how to create
the typed collection later when I have more time.  If you know of one that
maps a String to an Object rather than Object to Object, that might be more
efficient.

Thanks,
Barry



Quote:
> Barry,

> > Suppose a have a managed C++ class named Managed.  Is the following
> > acceptable?

> > #include <map>
> > #include <string>

> > using namespace std;
> > map<string, Managed> myManagedMap;
> > // or alternatively
> > map<string, * Managed> myManagedPointerMap;

> I don't think so (although I haven't tried it). Unmanaged types (such as
> map) can't directly hold of references to managed objects. (and you'd
> certainly need to hold __gc pointers, no way you could hold the actual
> classes, at least if we're talking __gc classes here).

> What is it exactly you're trying to do? Perhaps we can suggest a better
> way...
> --
> Tomas Restrepo




Wed, 05 Oct 2005 03:48:03 GMT  
 OK to use managed C++ classes in STL collections?

Quote:
> Suppose a have a managed C++ class named Managed.  Is the following
> acceptable?

> #include <map>
> #include <string>

> using namespace std;
> map<string, Managed> myManagedMap;
> // or alternatively
> map<string, * Managed> myManagedPointerMap;

map<string, gcroot<Managed*> > yourManagedPointerMap;

Ken



Wed, 05 Oct 2005 04:18:26 GMT  
 OK to use managed C++ classes in STL collections?
Hi Barry,

Quote:
> Just need to create a collection of managed classes the quickest way I
know
> how.   I'm new at .NET programming, although I've done a bit of reading on
> it and playing around some with C# and VB.NET code.  It looks like I'll
> start out with the System.Collections.Hashtable and figure out how to
create
> the typed collection later when I have more time.  If you know of one that
> maps a String to an Object rather than Object to Object, that might be
more
> efficient.

There isn't one, exactly. There's one mapping string to strings, though,
which is not what you're looking for.

--
Tomas Restrepo



Wed, 05 Oct 2005 04:19:01 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Problem using STL with managed C++

2. Problem using STL with managed C++

3. Using Managed Objects inside C++ Classes

4. Tutorial wanted for using a managed C++ class wrapper

5. using managed C++ class

6. using Managed dlls from Managed C++

7. using STL classes in a mixed C and C++ project

8. Managed C++ and specialized collections - guidance requested

9. Using unmanaged class/data structure in managed class

10. Using unmanaged nested classes of a managed class

11. MFC Collection class vs STL container

12. Going from MFC Collection classes to STL and HP-UX

 

 
Powered by phpBB® Forum Software