Greetings:
C++ CLR .Net 2
I have a ref class that I have created that wraps an unmanaged pointer. It
acts like a smart pointer for reference counted objects for a particular
library I am working in. I have overloaded the ->, *, assignment, and
equality operators. I have created a ! finalizer and call it from my
destructor. However, when I do so, the operator overload returns the type of
the wrapped pointer.
~MyClass()
{
this->!MyClass();
}
I get an error saying "WrappedPoi nter type doesn't have a function
!MyClass." I am having a hell of a time trying to call this. I am trying a
bunch of different things. Either it won't compile or I end in an endless
loop in the destructor. I know there is a way to do this.
???
Thanks
--
Howard Swope [hswope.swopeATn avteqDOTcom]
Senior Software Developer
Media Development
Navteq Traffic [ http://www.traffic.com] 3 1213
OK figured it out... simple... just added a little indirection:
public ref class FooMPtr
{
private:
Foo* niObj;
void Disp()
{
if (niObj != nullptr)
niObj->DecRefCount( );
}
!FooMPtr()
{
Disp();
}
internal:
FooMPtr()
{
niObj = nullptr;
}
FooMPtr(Foo* ptr)
{
niObj = ptr;
if (niObj != nullptr)
niObj->IncRefCount( );
}
FooMPtr(FooMPtr ^% mptr)
{
niObj = mptr;
if (niObj != nullptr)
niObj->IncRefCount( );
}
virtual ~FooMPtr()
{
Disp();
}
operator Foo*()
{
return niObj;
}
Foo& operator *()
{
return *niObj;
}
Foo* operator ->()
{
return niObj;
}
FooMPtr^ operator=(FooMP tr^% mptr)
{
if (niObj != mptr)
{
if (niObj != nullptr)
niObj->DecRefCount( );
niObj = mptr;
if (niObj != nullptr)
niObj->IncRefCount( );
}
return this;
}
FooMPtr^ operator=(Foo* ptr)
{
if (niObj != ptr)
{
if (niObj != nullptr)
niObj->DecRefCount( );
niObj = ptr;
if (niObj != nullptr)
niObj->IncRefCount( );
}
return this;
}
bool operator == (Foo* ptr)
{
return niObj == ptr;
}
bool operator != (Foo*ptr)
{
return niObj != ptr;
}
bool operator == (FooMPtr^% mptr)
{
return niObj == mptr;
}
bool operator != (FooMPtr^% mptr)
{
return niObj != mptr;
}
};
"Howard Swope" <hswopeATtraffi cDOTcomwrote in message
news:O7******** ******@TK2MSFTN GP02.phx.gbl...
Greetings:
C++ CLR .Net 2
I have a ref class that I have created that wraps an unmanaged pointer. It
acts like a smart pointer for reference counted objects for a particular
library I am working in. I have overloaded the ->, *, assignment, and
equality operators. I have created a ! finalizer and call it from my
destructor. However, when I do so, the operator overload returns the type
of the wrapped pointer.
~MyClass()
{
this->!MyClass();
}
I get an error saying "WrappedPoi nter type doesn't have a function
!MyClass." I am having a hell of a time trying to call this. I am trying a
bunch of different things. Either it won't compile or I end in an endless
loop in the destructor. I know there is a way to do this.
???
Thanks
--
Howard Swope [hswope.swopeATn avteqDOTcom]
Senior Software Developer
Media Development
Navteq Traffic [http://www.traffic.com]
"Howard Swope" <hswopeATtraffi cDOTcomwrote in message
news:O7******** ******@TK2MSFTN GP02.phx.gbl...
Greetings:
C++ CLR .Net 2
I have a ref class that I have created that wraps an unmanaged pointer. It
acts like a smart pointer for reference counted objects for a particular
library I am working in. I have overloaded the ->, *, assignment, and
equality operators. I have created a ! finalizer and call it from my
destructor. However, when I do so, the operator overload returns the type
of the wrapped pointer.
~MyClass()
{
this->!MyClass();
}
Try instead:
MyClass::!MyCla ss();
Or just move the code to an inline helper function called from both
finalizer and destructor.
>
I get an error saying "WrappedPoi nter type doesn't have a function
!MyClass." I am having a hell of a time trying to call this. I am trying a
bunch of different things. Either it won't compile or I end in an endless
loop in the destructor. I know there is a way to do this.
Yeah, you tried !MyClass(), which constructs a new MyClass and then uses the
logical negation operator, then destroys the temporary. The fully qualified
syntax I gave above should work.
>
???
Thanks
--
Howard Swope [hswope.swopeATn avteqDOTcom]
Senior Software Developer
Media Development
Navteq Traffic [http://www.traffic.com]
That's got it...
Thanks Ben
"Ben Voigt [C++ MVP]" <rb*@nospam.nos pamwrote in message
news:ep******** ******@TK2MSFTN GP02.phx.gbl...
>
"Howard Swope" <hswopeATtraffi cDOTcomwrote in message
news:O7******** ******@TK2MSFTN GP02.phx.gbl...
>Greetings:
C++ CLR .Net 2
I have a ref class that I have created that wraps an unmanaged pointer. It acts like a smart pointer for reference counted objects for a particular library I am working in. I have overloaded the ->, *, assignment, and equality operators. I have created a ! finalizer and call it from my destructor. However, when I do so, the operator overload returns the type of the wrapped pointer.
~MyClass() { this->!MyClass(); }
Try instead:
MyClass::!MyCla ss();
Or just move the code to an inline helper function called from both
finalizer and destructor.
>> I get an error saying "WrappedPoi nter type doesn't have a function !MyClass." I am having a hell of a time trying to call this. I am trying a bunch of different things. Either it won't compile or I end in an endless loop in the destructor. I know there is a way to do this.
Yeah, you tried !MyClass(), which constructs a new MyClass and then uses
the logical negation operator, then destroys the temporary. The fully
qualified syntax I gave above should work.
>> ???
Thanks -- Howard Swope [hswope.swopeATn avteqDOTcom] Senior Software Developer Media Development Navteq Traffic [http://www.traffic.com] This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: KK |
last post by:
Hi, im working on this bigInt class. Need help writing algorithm for
the operator*, andy help will be appreciated. Thanks in advance
bigInt.h
===================================================================================
//class bigInt implements big integers by storing the digits of a big
//integer in a private vector data member called digit. Since it uses
a
//vector the size of the big integer can be indefinitely large. This...
|
by: Chris |
last post by:
To me, this seems rather redundant. The compiler requires that if you
overload the == operator, you must also overload the != operator. All I do
for the != operator is something like this:
public static bool operator !=(MyType x, MyType y)
{
return !(x == y);
}
That way the == operator handles everything, and extra comparing logic isn't
|
by: BravesCharm |
last post by:
BravesCharm Dec 7, 10:57 am show options
Newsgroups: microsoft.public.dotnet.distributed_apps
From: "BravesCharm" <mastrauc...@gmail.com>
Date: 7 Dec 2004 10:57:40 -0800
Local: Tues, Dec 7 2004 10:57 am
Subject: Have trouble with reference counts!
Reply | Reply to Author | Forward | Print | Individual Message | Show
original | Remove | Report Abuse
|
by: esafran |
last post by:
I've defined a class, but now I want to Define a Finalizer
(destructor)...
How do I call the Base Finalizer???, void Finalize() is a protected
override method and Type.GetType Does not work.
Hoe do I call it?
private void DefineFinalizer(TypeBuilder typeBuilder)
{
|
by: Bill foust |
last post by:
I'm running into a situation there I think an operator overload would solve
the issue, but I'm unable to make it work for some reason. If anyone can
help here I would appreciate it.
I have a base class that is common to many other classes.
public class Base
....
end class
I have 2 seperate classes that inherit from base
| |
by: richard.parker |
last post by:
Hello,
I need to overload operator new with affecting the system libraries.
Has anyone done this? I've got 2 static libraries and application
source code where the operator needs to be overloaded, but I need to
link with the system libraries (frameworks) and I DO NOT want my
overloads to be mapped to them. I'm working with some code that is
currently working on Win32 but also needs to work on the Mac. Under
windows this is very...
|
by: Jeremy Chaney |
last post by:
I have an application written in C# that uses objects written in a
managed C++ DLL. When I exit my app, my C# classes have their
destructors called, but the MC++ objects that those classes hold
references to do not get invoked (I can observe this from both
breakpoints in the code, and trace output to the console).
I was under the impression that when my C# object goes out of scope, it
would automatically dispose of all of the references...
|
by: =?ISO-8859-1?Q?Tom=E1s_=D3_h=C9ilidhe?= |
last post by:
Operator overloads are just like any other member function, you
can make them do whatever you want. However, of course, we might
expect them to behave in a certain way. The ++ operator should perform
some sort of increment, the / operator should do something along the
lines of division.
Do you think it would have been worthwhile for the C++ Standard to
"codify" this expected use of operator overloads? I'll be specific:
Let's say you...
|
by: Paul E Collins |
last post by:
This code won't compile because "the modifier 'abstract' is not valid for
this item".
abstract class X
{
public abstract static bool operator >(X a, X b);
public abstract static bool operator <(X a, X b);
}
Why is that? -- apart from the obvious reason that the specification doesn't
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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...
| |
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...
|
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,...
|
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...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |