|
Thank you Roger ..
Hope this will work ...
|
|
|
|
|
Hi,
In some of the singleton classes, I have seen that
People are keeping the destructor of singleton class in 'Public' Section of class.
Is it right to allow some one from outside to delete the singleton Object.
Thanks in advance,
Vinod.C.S
|
|
|
|
|
Vinod CS wrote: Is it right to allow some one from outside to delete the singleton Object.
how could you delete the object of Singleton class from outside, when it is not exposed to you. whole singleton concept is depend on static data!, fronm which you manage the lifetime of singleton class!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
I was taking abt implementing singleton clas in Threadsafe way using 'new':
mySingletonClass* mySingletonClass::GetInstance
{
if( 0 == m_pmySingletonObject )
{
m_pmySingletonObject = new mySingletonClass;
}
return pmySingletonObject;
}
Thnaks in advance,
Vinod.C.S
|
|
|
|
|
Vinod CS wrote: Threadsafe
then you might have to use syncronization object!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
By providing a public Destroy function that will delete the instance pointer. This way, you enforce a correct usage of the class.
As the pointer is deleted from within a member function, the destructor can be made private.
|
|
|
|
|
Cedric Moonen wrote: As the pointer is deleted from within a member function, the destructor can be made private.
Hi Cedric,
I doesn't understand what you want to say.. is there is any short coming in my comment!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
I don't know if that is the reason but there is a bug in the VC6 compiler: even if you provide a Destroy public method:
void CSingleton::Destroy()<br />
{<br />
if (m_pInstance)<br />
delete m_pInstance;<br />
}
You will have a compilation error saying that the destructor is public. So, to overcome this bug you have to make your destructor public.
I don't know if that is the reason but I encountered this problem before already.
|
|
|
|
|
Vinod CS wrote: People are keeping the destructor of singleton class in 'Public' Section of class.
When they do it is an error.
Normaly it is a static const object living in a global function.
Also, its c'tors and d'tors can be protected and construction made by a friend -factory class.
Or, the access is not on the whole class-interface, but only an Interface-pointer.
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
Hello,
I create a "MFC application" project in MSVC 2005.
But I want to add a class ref from tThread.
For example,
public ref class tThread
{
public:
XXXXXXXXXXXXX
};
I add this code in the Form1.h.
But it has a default class From1.
I create a new header file to include.
#include "mythread.h"
But it come some errors.
This is mythread.h
///////////////////////////
#ifndef MYTHREAD_H
#define MYTHREAD_H
public ref class tThread
{
public:
static void Threadsend();
}
#endif
/////////////////////////////
This is mythread.cpp
#include "mythread"
using namespace System::Threading;
static void Threadsend(){
Thread::Sleep( 0 );
}
What's wrong with my code or are there better method to do it?
Appreciate your reply.
Thank you.
Jane
|
|
|
|
|
Hi,
i never heared about a "ref class", but google lists some sites about it.
What do you like to do exactly?
Greetz
|
|
|
|
|
We have ref class and value class (on the CLI/C++) its better I write of MSDN
A ref class or ref struct can inherit from zero or more managed interfaces and zero or one ref types. A value class or value struct can only inherit from zero or more managed interfaces.
public ref class Items
{
private : int size;
....
};
public value class differ
{
private:
String^ str;
....
};
|
|
|
|
|
Hamid. wrote: We have ref class and value class (on the CLI/C++)
Seems as if you are in the wrong Forum...
Try your question in theManaged C++-Forum[^]
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
But I dont have any question.
|
|
|
|
|
There is no problem@@.
It works.
|
|
|
|
|
Hello,
I am confused about the type of vc++ .NET.
I want to use the string typed in the Textbox.
The property "Text" of Textbox has the type "string^".
I want to change it to char*.
I use the TextBox->Text->ToCharArray, but it is not char* type.
It is wchar_t type.
How could I convert the string^ type to char*?
Appreciate your reply.
Thank you.
Jane
|
|
|
|
|
|
|
Hamid. wrote: You asked on the wrong forum it was better you asked (Managed) C++/CLI[^].
i just going to do same.. you beat me this time!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Do you want to learning C++.Net?
|
|
|
|
|
Hamid. wrote: Do you want to learning C++.Net
yea want to.. any online tutor
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
If you remember we have a member on the codeproject Mr Nishant Sivakumar it has a good site see C++/CLI [^] for start.;)
|
|
|
|
|
Hamid. wrote: If you remember we have a member on the codeproject Mr Nishant Sivakumar it has a good site see C++/CLI [^] for start.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Thx
|
|
|
|
|