473,396 Members | 1,871 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,396 software developers and data experts.

Managed pointers to pointers

Hi, I've been trying to update some old C++ code and when i came across
this:

MyClass** ppOut

I changed it to:

MyManagedClass^% ppOut
However - it doesn't work exactly the same because I am unable to pass
nullptr for one of those parameters. How can I replicate pointers to
pointers?

Thanks,
Nov 20 '06 #1
3 1106

Mark Ingram a écrit :
Hi, I've been trying to update some old C++ code and when i came across
this:

MyClass** ppOut

I changed it to:

MyManagedClass^% ppOut
"MyManagedClass^%" (tracking reference to a managed handle) is the
managed equivalent of "MyClass*&" (reference to a pointer). It is NOT
the equivalent of a pointer to a pointer.
However - it doesn't work exactly the same because I am unable to pass
nullptr for one of those parameters. How can I replicate pointers to
pointers?
You cannot do it directly, but on the other hand is shouldn't be
necessary in most cases. In native C and C++, pointers to pointers (to
pointers....) are mainly usefull for multi-dimensionnal arrays - which
are handled differently in managed code.

On the other hand, if you were using a pointer to a pointer in native
code as a function parameter, you should use the [Out] attribute
instead.

Show us the original code so that we can best advise you on how to
replace it.

Arnaud
MVP - VC

Thanks,
Nov 20 '06 #2
ad******@club-internet.fr wrote:
>
Show us the original code so that we can best advise you on how to
replace it.

Arnaud
MVP - VC

>>Thanks,

After a bit of hunting I've found interior_ptr<MyManagedClasswhich
works exactly as I was hoping.

Basically:

MyManagedClass^ pTest;
MyFunction(&pTest);

void MyFunction(interior_ptr<MyManagedClassppTest)
{
if (ppTest != nullptr)
{
*ppTest = gcnew MyManagedClass();
}
}

Is that ok?
Nov 20 '06 #3

"Mark Ingram" <no****@nowhere.comwrote in message
news:Oy**************@TK2MSFTNGP04.phx.gbl...
ad******@club-internet.fr wrote:
>>
Show us the original code so that we can best advise you on how to
replace it.

Arnaud
MVP - VC

>>>Thanks,


After a bit of hunting I've found interior_ptr<MyManagedClasswhich works
exactly as I was hoping.

Basically:

MyManagedClass^ pTest;
MyFunction(&pTest);

void MyFunction(interior_ptr<MyManagedClassppTest)
Are you missing a ^, as in interior_ptr<MyManagedClass^>?
{
if (ppTest != nullptr)
{
*ppTest = gcnew MyManagedClass();
}
}

Is that ok?

Nov 20 '06 #4

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

Similar topics

2
by: Craig Kenisston | last post by:
Which are the disadvantage of use pointers in the code ? In general. I know it turns your code into unsafe code, because even you have to flag it ... but does it still 100% managed code, right...
3
by: Dave | last post by:
I'm at a point where I would really like to focus in on learning .NET but am having a hard time deciding which language to use. I learned to program in C++ but have spent quite a bit of time using...
2
by: bor_kev | last post by:
Hi, First of all, i want to use the new managed class syntax and STL.NET under Microsoft Visual (C++) Studio 2005 Beta. I read in a Microsoft...
3
by: vijay.gandhi | last post by:
Hi, I am trying to convert some unmanaged code (C++) to managed code (using C++/CLI). 1) One of the functions used returns a void* which I need to cast into a handle of a managed object. Can...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
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...

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.