Anyone know a direct translation for this C# code? I know I can make a new
function, of course, but that's clumsy.
assume (o is IDisposable)
MethodInvoker d = o.Dispose;
I tried taking the address of the destructor, that either tries to give me
protected void Dispose(bool) with an error (it's the wrong argument list) or
tells me {dtor} is not a member of IDisposable.
This is all on VS2005 SP1.
Automatic implementation of IDisposable screwed up this one! 8 2126
"Ben Voigt [C++ MVP]" <rb*@nospam.nospamwrote in message
news:#x*************@TK2MSFTNGP06.phx.gbl...
Anyone know a direct translation for this C# code? I know I can make a
new function, of course, but that's clumsy.
assume (o is IDisposable)
MethodInvoker d = o.Dispose;
I tried taking the address of the destructor, that either tries to give me
protected void Dispose(bool) with an error (it's the wrong argument list)
or tells me {dtor} is not a member of IDisposable.
Does this work?
////////////////////////////////////////////////////////////////////////
ref class disposableclass
{
public:
disposableclass()
{
}
~disposableclass()
{
this->!disposableclass();
}
!disposableclass()
{
}
};
....
disposableclass ^o = gcnew disposableclass();
MethodInvoker ^d = gcnew MethodInvoker(o,
&disposableclass::~disposableclass);
////////////////////////////////////////////////////////////////////////
Mark
--
Mark Salsbery
Microsoft MVP - Visual C++
Mark Salsbery [MVP] wrote:
"Ben Voigt [C++ MVP]" <rb*@nospam.nospamwrote in message
news:#x*************@TK2MSFTNGP06.phx.gbl...
>Anyone know a direct translation for this C# code? I know I can make a new function, of course, but that's clumsy.
assume (o is IDisposable) MethodInvoker d = o.Dispose;
I tried taking the address of the destructor, that either tries to give me protected void Dispose(bool) with an error (it's the wrong argument list) or tells me {dtor} is not a member of IDisposable.
Does this work?
Your code compiles cleanly. So my situation is actually less general than I
first thought.
Change disposableclass so that it inherits System::Windows::Forms::Form, for
instance. Then:
..\CppTestJunk.cpp(28) : error C2248: 'disposableclass::Dispose' : cannot
access protected member declared in class 'disposableclass'
..\CppTestJunk.cpp(21) : compiler has generated 'disposableclass::Dispose'
here
..\CppTestJunk.cpp(8) : see declaration of 'disposableclass'
..\CppTestJunk.cpp(28) : error C3352: 'void disposableclass::Dispose(bool)' :
the specified function does not match the delegate type 'void (void)'
>
////////////////////////////////////////////////////////////////////////
ref class disposableclass
{
public:
disposableclass()
{
}
~disposableclass()
{
this->!disposableclass();
}
!disposableclass()
{
}
};
...
disposableclass ^o = gcnew disposableclass();
MethodInvoker ^d = gcnew MethodInvoker(o,
&disposableclass::~disposableclass);
////////////////////////////////////////////////////////////////////////
Mark
"Ben Voigt [C++ MVP]" <rb*@nospam.nospamwrote in message
news:ew**************@TK2MSFTNGP03.phx.gbl...
>
Your code compiles cleanly. So my situation is actually less general than
I first thought.
Change disposableclass so that it inherits System::Windows::Forms::Form,
for instance.
In that case, Dispose() is hidden (by access level change) by the Form
class and re-exposed through its Close() member, so yeah, that won't work.
"Mark Salsbery [MVP]" <MarkSalsbery[MVP]@newsgroup.nospamwrote in message
news:#e**************@TK2MSFTNGP06.phx.gbl...
>
In that case, Dispose() is hidden (by access level change) by the Form
class and re-exposed through its Close() member, so yeah, that won't work.
re-exposed is the wrong wording...I meant iDispose()'s functionality is
re-exposed through Close().
The derived class would need to implemented in a similar fashion.
Mark
--
Mark Salsbery
Microsoft MVP - Visual C++
>
"Mark Salsbery [MVP]" <MarkSalsbery[MVP]@newsgroup.nospamwrote in message
news:#e**************@TK2MSFTNGP06.phx.gbl...
"Ben Voigt [C++ MVP]" <rb*@nospam.nospamwrote in message
news:ew**************@TK2MSFTNGP03.phx.gbl...
>> Your code compiles cleanly. So my situation is actually less general than I first thought.
Change disposableclass so that it inherits System::Windows::Forms::Form, for instance.
In that case, Dispose() is hidden (by access level change) by the Form
class and re-exposed through its Close() member, so yeah, that won't work.
..NET doesn't allow changing access level at inheritance. But the C++/CLI
compiler is considering the destructor reference to mean protected
Dispose(bool) instead of public Dispose(void).
"Ben Voigt [C++ MVP]" <rb*@nospam.nospamwrote in message
news:0B**********************************@microsof t.com...
>
.NET doesn't allow changing access level at inheritance.
Yeah I always believe that in C#.
What magic does C++ use to make this fail to compile:
System::Windows::Forms::Form ^frm = gcnew
System::Windows::Forms::Form();
frm->Dispose();
???
Duh - C++ doesn't let you call Dispose().
///////////////////////////////////////
ref class disposableclass : public System::Windows::Forms::Form
{
public:
disposableclass()
{
}
~disposableclass()
{
this->!disposableclass();
}
!disposableclass()
{
}
};
....
disposableclass ^o = gcnew disposableclass();
o->~disposableclass(); // This is ok
MethodInvoker ^d = gcnew MethodInvoker(o,
&disposableclass::~disposableclass); // This is not ok?
///////////////////////////////////////
Bug?
Not sure what you meant by that last comment.
delete (some_tracking_handle);
does exactly call Dispose on the object if it implements IDisposable.
"Mark Salsbery [MVP]" <MarkSalsbery[MVP]@newsgroup.nospamwrote in message
news:uH**************@TK2MSFTNGP03.phx.gbl...
Duh - C++ doesn't let you call Dispose().
///////////////////////////////////////
ref class disposableclass : public System::Windows::Forms::Form
{
public:
disposableclass()
{
}
~disposableclass()
{
this->!disposableclass();
}
!disposableclass()
{
}
};
...
disposableclass ^o = gcnew disposableclass();
o->~disposableclass(); // This is ok
MethodInvoker ^d = gcnew MethodInvoker(o,
&disposableclass::~disposableclass); // This is not ok?
///////////////////////////////////////
Bug?
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Noloader |
last post by:
Hello,
Access XP, SQL Server 2000
Is it possible to hide a SP under Queries in Access, yet still be able
to Execute it from Access? (Similar to hiding Tables, then using
Views)
We hooked...
|
by: Alexander |
last post by:
I am building a little unique dialog editor and have derived some new
classes like DButton, DLabel and DTextBox. The user adds these
Controls to a panel which is part of a class Document which is...
|
by: Bob Weiner |
last post by:
What is the purpose of hiding intead of overriding a method? I have googled
the question but haven't found anything that makes any sense of it.
In the code below, the only difference is that...
|
by: Amber |
last post by:
The DataGrid allows you to make columns visible or invisible on demand
- even edit and other special columns. This article will show you how
it is done.
Some developers have reported problems...
|
by: Tony Vitonis |
last post by:
Hello. I've written an app that I want to "live" in the system tray.
I want it to start up with just a tray icon showing, and if the user
selects "Settings..." from the icon's context menu, to...
|
by: Dennis |
last post by:
Ok, I'm trying to dispose of every object that I create that has a dispose
method based on advice from this newsgroup. However, I'm not sure how to
dispose of the following object that was created...
|
by: Steve954 |
last post by:
I recently installed and started using VS2005 on a Windows XP Pro machine.
When creating a new windows forms project I find that I am unable to hide any
forms using the me.hide() or me.visible =...
|
by: Alex |
last post by:
Hello all,
I have a main form(say "form1") .i want to display another form(say
"form2") on occuring of an event (say a button click) and want to hide
it after some time so that it will again...
|
by: Sh4wn |
last post by:
Hi,
first, python is one of my fav languages, and i'll definitely keep
developing with it. But, there's 1 one thing what I -really- miss:
data hiding. I know member vars are private when you...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
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...
|
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,...
|
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...
|
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...
|
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: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
| |