473,657 Members | 2,513 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C++/CLI issue: using STL and CLI value types (C# structs)

I'm having a major problem trying to use value types like
System::Drawing ::Rectangle with std::vector. Is it possible to use STL
containers with these type of objects, or am I just doing something wrong?

Thanks!

[ -- code snippet -- ]
using namespace System::Drawing ;
#include <vector>

public ref class Base
{
static void GetQuads( Base^ root )
{
std::vector<Rec tangleq;
}
};
gives this error

C:\Program Files\Microsoft Visual Studio 8\VC\include\xu tility(1290) :
error C4439: 'std::_Ptr_cat' : function definition with a managed type
in the signature must have a __clrcall calling convention
2 C:\Program Files\Microsoft Visual Studio
8\VC\include\xm emory(226) : see reference to function template
instantiation 'std::_Nonscala r_ptr_iterator_ tag
std::_Ptr_cat<_ Ty*,_Ty*>(_T1 &,_T2 &)' being compiled
2 with
2 [
2 _Ty=System::Dra wing::Rectangle ,
2 _T1=System::Dra wing::Rectangle *,
2 _T2=System::Dra wing::Rectangle *
2 ]
2 C:\Program Files\Microsoft Visual Studio
8\VC\include\ve ctor(1083) : see reference to function template
instantiation 'void
std::_Destroy_r ange<System::Dr awing::Rectangl e,std::allocato r<_Ty>>(_Ty
*,_Ty *,_Alloc &)' being compiled
2 with
2 [
2 _Ty=System::Dra wing::Rectangle ,
2 _Alloc=std::all ocator<System:: Drawing::Rectan gle>
2 ]
2 C:\Program Files\Microsoft Visual Studio
8\VC\include\ve ctor(1082) : while compiling class template member
function 'void std::vector<_Ty >::_Destroy(Sys tem::Drawing::R ectangle
*,System::Drawi ng::Rectangle *)'
2 with
2 [
2 _Ty=System::Dra wing::Rectangle
2 ]
2 c:\depot-jmatzen-mouse\depot\gam e14\src\engine\ ui\Base.h(145)
: see reference to class template instantiation 'std::vector<_T y>' being
compiled
2 with
2 [
2 _Ty=System::Dra wing::Rectangle
2 ]
Aug 27 '06 #1
4 4552
John wrote:
I'm having a major problem trying to use value types like
System::Drawing ::Rectangle with std::vector. Is it possible to use
STL containers with these type of objects, or am I just doing
something wrong?
No, you're not doing anything wrong - it justs doesn't work.

There's a feature known as STL/CLR that was intended to be included in VC
2005 but they weren't able to get it done in time. When it's eventually
released, it'll directly address the kind of thing you're trying to do. In
the meantime, you have to settle with using framework containers for
framework objects.

See

http://msdn.microsoft.com/msdnmag/is...C/default.aspx

for some background on STL/CLR. AFIAK, no release date for STL/CLR has been
announced

-cd
Aug 27 '06 #2
"Carl Daniel [VC++ MVP]" wrote
>I'm having a major problem trying to use value types like
System::Drawin g::Rectangle with std::vector. Is it possible to use
STL containers with these type of objects, or am I just doing
something wrong?

No, you're not doing anything wrong - it justs doesn't work.
The particular diagnostic sounds rather academic. Did you try to
downgrade/disable the error? I guess that won't work because
vector will use placement new.

Anyway for Rectangle, this might be used in COM Interop
and therefore should have sequential layout, which should
mean it's binary compatible with the corresponding native
type (RECT). So just using std::vector<REC Twith some
conversions should work just fine.

-hg
Aug 28 '06 #3
John wrote:
I'm having a major problem trying to use value types like
System::Drawing ::Rectangle with std::vector. Is it possible to use STL
containers with these type of objects, or am I just doing something wrong?
Hi John,
try storing gcroot or auto_gcroot pointers of the managed objects in
order to embed them within native types like std:vector:

std::vector<gcr oot<Rectangle^> q;

See "Mix Types Safely and Correctly" in
http://msdn.microsoft.com/library/de...CplusCLIBP.asp

Semmel

Aug 28 '06 #4
Semmel wrote:
try storing gcroot or auto_gcroot pointers of the managed objects in
order to embed them within native types like std:vector:

std::vector<gcr oot<Rectangle^> q;
A possible problem with this is that Rectangle becomes a GC type, which
means a hidden wrapper is created around it. This is called boxing, and
it's done implicitly. I'd consider using List<Rectangle> , and gcrooting
that if needed.

If gcroot is used, it requires a manual call to delete, as gcroot is
like a naked pointer. auto_gcroot is the exception safe version, but I'm
not sure if it can be stored in a container safely. It could be like
auto_ptr, which doesn't mix with STL.

Tom
Aug 28 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1191
by: Sathyaish | last post by:
Structs are value types, strings are ref types. If you have something like this: struct foo { System.String str; } foo TheDayToday;
1
1816
by: Rafael Veronezi | last post by:
Just to fix, correct me if I am wrong... With reference types (objects), if I assign an object to another, the assignment will be the address of the object, and not a copy of it's contents right? With value types (structs), if I assign an object to another, I'll be copying it's data to the left side of the assignment, and not it's address. This is valid with method parameters too, like, if I pass an object as a parameter, i'll be...
6
1976
by: Kenneth Baltrinic | last post by:
I have the following routine that is always throwing the error at the end. It never returns from within the foreach loop because the if expression is always evaluating to false apparently. This is something of a problem. The comparison is between two objects (Handler.Data is defined as returning an object.), but these objects are always nothing more than boxed value types (either strings or ints or an int based enumeration). If for the...
2
2484
by: Fuzzy | last post by:
I have defined a struct in my application that contains 3 integers that maintain state information. I have a lot of these structs in time-critical portions of my app, so they must be as fast as possible. I also log previous values in arrays, so data size can't be ignored. The data is such that I can implement value semantics by implementing IComparable.CompareTo and overriding all the comparison operators as well as Object.Equals(object...
9
3182
by: John | last post by:
If a value type is immutable, I guess it's threadsafe to read it? But not threadsafe to assign a new value to it (can any value type be truely immutable? Isn't assigning a totally new value to it, like doing an modification, when no references are involved? I don't know enough about CLR) At the moment the whole: lock(anobject) {
24
2609
by: ALI-R | last post by:
Hi All, First of all I think this is gonna be one of those threads :-) since I have bunch of questions which make this very controversial:-0) Ok,Let's see: I was reading an article that When you pass a Value-Type to method call ,Boxing and Unboxing would happen,Consider the following snippet: int a=1355; myMethod(a); ......
5
2094
by: Zach | last post by:
When it is being said that, "value types are created on the stack or inline as part of an object". If a value type is created in an object, and that object is being called, the value type in that object, is still created on the stack, I would say, so I don't understand this inline business. Apart from the fact that it is my understanding that "inline" as it exists in C++ doesn't exist in C#. Could someone please shed some light on this...
12
2693
by: Edward Diener | last post by:
Given value class X { public: // Not allowed: X():i(100000),s(10000) { } // Allowed void InitializeDefaults() { i = 100000; s = 10000; } private: int i;
9
1769
by: John | last post by:
I'm sorry if this is sounding like somewhat of a noob question. I'm loading in a large binary array of 8x8 double precision floating point matrices, right now this is defined something like struct Mat8x8 { double M11; double M12;
0
8421
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8844
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8742
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8518
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8621
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7354
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5643
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1971
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.