All,
I am developing an Object that wraps an old C library. Baeed upon how the object will be used I decided the best bet would be to make the object a singleton.
Additionally, because the object is working with unmanaged resources it should implement a dispose method to ensure that those resounrce are freed.
Here is the basic code for the object's constructor and dispose method
public sealed class IAClientImport : IDisposable
{
private static volatile IAClientImport instance;
private static object syncRoot = new Object();
private bool _Disposed = false;
private IAClientImport() {}
public static IAClientImport Instance
{
get
{
if ( instance == null )
{
lock ( syncRoot )
{
if ( instance == null )
instance = new IAClientImport();
}
}
return instance;
}
public void Dispose()
{
Dispose( true );
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if ( !this._Disposed )
{
if ( disposing ) { /*Dispose Managed Resources Here*/ }
//Dispose Managed Reources - The Handle To The IA Client Object
}
this._Disposed = true;
}
~IAClientImport()
{
Dispose(false);
}
}
The problem that I am having is that when I attempt to compile the object I get the following two errors
(1489): 'FNIS.InputAccel.IAClientImport.Dispose(bool)' : new protected member declared in sealed class
(1489): 'FNIS.InputAccel.IAClientImport.Dispose(bool)' is a new virtual member in a sealed class 'FNIS.InputAccel.IAClientImport'
I am a bit confused as to what I need to change in order to ensure that the unmanaged resources in the object get disposed of properly while at the same time holding to the singleton design pattern.
Any help is appreciated.
Thanks! 2 6314
The error is probably because proteced members do not make sense in a sealed
class. From a sealed class cannot be inherited from but protected members
can be accessed from the class itself and derived classes.
You should make the method private or public instead.
--
cody
Freeware Tools, Games and Humour http://www.deutronium.de.vu || http://www.deutronium.tk
"Dan" <Da*@discussions.microsoft.com> schrieb im Newsbeitrag
news:AC**********************************@microsof t.com... All,
I am developing an Object that wraps an old C library. Baeed upon how the
object will be used I decided the best bet would be to make the object a
singleton. Additionally, because the object is working with unmanaged resources it
should implement a dispose method to ensure that those resounrce are freed. Here is the basic code for the object's constructor and dispose method
public sealed class IAClientImport : IDisposable {
private static volatile IAClientImport instance; private static object syncRoot = new Object(); private bool _Disposed = false;
private IAClientImport() {}
public static IAClientImport Instance {
get {
if ( instance == null ) { lock ( syncRoot ) { if ( instance == null ) instance = new IAClientImport(); } }
return instance;
}
public void Dispose() { Dispose( true ); GC.SuppressFinalize(this); }
protected virtual void Dispose(bool disposing) { if ( !this._Disposed ) {
if ( disposing ) { /*Dispose Managed Resources Here*/ }
//Dispose Managed Reources - The Handle To The IA Client Object
}
this._Disposed = true;
}
~IAClientImport() { Dispose(false); }
}
The problem that I am having is that when I attempt to compile the object
I get the following two errors (1489): 'FNIS.InputAccel.IAClientImport.Dispose(bool)' : new protected
member declared in sealed class (1489): 'FNIS.InputAccel.IAClientImport.Dispose(bool)' is a new virtual
member in a sealed class 'FNIS.InputAccel.IAClientImport'
I am a bit confused as to what I need to change in order to ensure that
the unmanaged resources in the object get disposed of properly while at the
same time holding to the singleton design pattern. Any help is appreciated.
Thanks!
Hi Dan,
I think that it's because the class is sealed, then it has no point in
declare a method protected or virtual, you will no have any derived classes
that can override it. nor access it.
Cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Dan" <Da*@discussions.microsoft.com> wrote in message
news:AC**********************************@microsof t.com... All,
I am developing an Object that wraps an old C library. Baeed upon how the
object will be used I decided the best bet would be to make the object a
singleton. Additionally, because the object is working with unmanaged resources it
should implement a dispose method to ensure that those resounrce are freed. Here is the basic code for the object's constructor and dispose method
public sealed class IAClientImport : IDisposable {
private static volatile IAClientImport instance; private static object syncRoot = new Object(); private bool _Disposed = false;
private IAClientImport() {}
public static IAClientImport Instance {
get {
if ( instance == null ) { lock ( syncRoot ) { if ( instance == null ) instance = new IAClientImport(); } }
return instance;
}
public void Dispose() { Dispose( true ); GC.SuppressFinalize(this); }
protected virtual void Dispose(bool disposing) { if ( !this._Disposed ) {
if ( disposing ) { /*Dispose Managed Resources Here*/ }
//Dispose Managed Reources - The Handle To The IA Client Object
}
this._Disposed = true;
}
~IAClientImport() { Dispose(false); }
}
The problem that I am having is that when I attempt to compile the object
I get the following two errors (1489): 'FNIS.InputAccel.IAClientImport.Dispose(bool)' : new protected
member declared in sealed class (1489): 'FNIS.InputAccel.IAClientImport.Dispose(bool)' is a new virtual
member in a sealed class 'FNIS.InputAccel.IAClientImport'
I am a bit confused as to what I need to change in order to ensure that
the unmanaged resources in the object get disposed of properly while at the
same time holding to the singleton design pattern. Any help is appreciated.
Thanks! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Sean Dettrick |
last post by:
Hi,
apologies for yet another Singleton posting.
From reading around previous postings etc, I've cobbled together two
Singleton template definitions - one that returns a reference, and one
that...
|
by: Tim Clacy |
last post by:
Is there such a thing as a Singleton template that actually saves
programming effort?
Is it possible to actually use a template to make an arbitrary class a
singleton without having to:
a)...
|
by: Ethan |
last post by:
Hi,
I have a class defined as a "Singleton" (Design Pattern). The codes are
attached below.
My questions are:
1. Does it has mem leak? If no, when did the destructor called? If yes, how
can I...
|
by: Pelle Beckman |
last post by:
Hi,
I've done some progress in writing a rather simple
singleton template.
However, I need a smart way to pass constructor arguments
via the template.
I've been suggested reading "Modern C++...
|
by: Tony Johansson |
last post by:
Hello!
I have a class called Outdoors which is a singleton see below for definition
and a main that call this instance method.
Now to my problem this piece of code doesn't compile I get the...
|
by: yccheok |
last post by:
hello, in a singleton design, i trying to make my parent class having
protected constructor and destructor. however, the compiler give me
error when my child, trying to delete itself through parent...
|
by: Damien |
last post by:
Hi all,
I'm using a pretty standard C++ Singleton class, as below:
template <typename T>
class Singleton
{
public:
static T* Instance()
{
|
by: weaknessforcats |
last post by:
Design Pattern: The Singleton
Overview
Use the Singleton Design Pattern when you want to have only one instance of a class. This single instance must have a single global point of access. That...
|
by: James Kanze |
last post by:
On Apr 11, 12:09 am, Ron Eggler <t...@example.comwrote:
That's usually a feature, not a bug, where singletons are
concerned. In general, I avoid ever deleting a singleton.
From the...
|
by: stevewilliams2004 |
last post by:
I am attempting to create a singleton, and was wondering if someone
could give me a sanity check on the design - does it accomplish my
constraints, and/or am I over complicating things. My design...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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: 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: 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...
| |