473,322 Members | 1,610 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Implicit conversion and operator overloading

I'm seeing some strange behaviour:
i have a managed wrapper class that wraps around unmanaged object, i want to
convert back and forth between managed and unmanaged object, so i have
overloaded conversion operators.

namespace ManagedWorld{
ref class ManagedFoo{
private:
Unmanaged::Foo* pFoo;
public:
ManagedFoo(Unmanaged::Foo * p) : pFoo(p) {};
Unmanaged::Foo* GetInternalObject() { return pFoo; }
static operator Unmanaged::Foo* (ManagedFoo^ rfoo){
return rfoo->GetInternalObject();
}
static operator ManagedFoo^(Unmanaged::Foo *p){
return gcnew ManagedFoo( p );
}
}
}// managed world namespace.

Using this unmanaged class from C#.

ManagedFoo^ myfoo = nullptr;
if( myfoo == nullptr ) // Line 2
Console.WriteLine("it is nullptr");
if( nullptr == myfoo)
Console.WriteLine("this works fine");

In Line 2, it does implicit conversion, then it calls this function
static operator Unmanaged::Foo* (ManagedFoo^ rfoo){
return rfoo->GetInternalObject();
}

I want to know why it does implicit conversion on handles before comparing?

Thanks
Charles
Nov 17 '05 #1
0 920

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

Similar topics

4
by: Simon Ford | last post by:
Hi All, I'm having trouble understanding exactly how I can do some specific implicit casting. There are two problems here; does anyone know what I should be doing? //---------- // (1)...
4
by: Master of C++ | last post by:
Hi, This is a simple question. In the following example, .. class Vector .. { .. private: .. int *Numbers; .. int vLength; ..
1
by: Christophe Poucet | last post by:
Hellom I have an issue with implicit conversions. Apparently when one calls an operator on a class Y which has a conversion operator to class X which has the operator . Sadly it will not do...
1
by: Kel Good | last post by:
Hello, I recently created a structure in C# that offers several implicit conversion, hoping I could then reference the C# project from a VB.Net project, and use this object in VB.Net. It does...
11
by: Steve Gough | last post by:
Could anyone please help me to understand what is happening here? The commented line produces an error, which is what I expected given that there is no conversion defined from type double to type...
9
by: Girish | last post by:
Im trying to understand implicit type conversions from object -> string and vice versa. I have two classes, one Driver and one called StringWrapper. These are just test classes that try and...
25
by: Chad Z. Hower aka Kudzu | last post by:
I have defined some implicit convertors so that I can do: MyStruct x = 4; The implicit convert the 4 into MyStruct. But its essentially a copy constructor and thus if I had: MyStruct x;...
36
by: Chad Z. Hower aka Kudzu | last post by:
I have an implicit conversion set up in an assembly from a Stream to something else. In C#, it works. In VB it does not. Does VB support implicit conversions? And if so any idea why it would work...
8
by: jonpb | last post by:
Hi, Is it possible to define a implicit operator from base to derived types in C#? I have a Point class and would like to derive a Vector class from it and add a couple new vector related...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.