|
This is a non-compliant issue with VC++ compiler. The code should
compile, but it will not in VC++ 6.0 or 7.1.
As a workaround, you can create a friend class and let it delete your
singleton.
Here's a workaround example:
template<typename t="">
class Singleton
{
protected:
Singleton(){}
~Singleton(){}
Singleton(const Singleton&);
Singleton& operator=(const Singleton&);
public:
class FriendClass
{
public:
FriendClass():m_MyClass(new T()){}
~FriendClass(){delete m_MyClass;}
T* m_MyClass;
};
static T& Instance() {
static FriendClass Instance;
return *Instance.m_MyClass;
//Will not compile with the following code in VC++ 6.0 or 7.1
// static T Instance;
// return Instance;
}
};
//The above Singleton template can be used two ways.
//Either by deriving from it, or by declaring the friend class with
fully
//qualified template, and calling the instance member function with
fully
//qualified template function.
class Widget {
private:
Widget(){}
~Widget(){}
Widget& operator=(const Widget&);
Widget(const Widget&);
public:
friend class Singleton<widget>::FriendClass;
int m_i;
};
class foo : public Singleton<foo>{
private:
foo(){}
~foo(){}
foo& operator=(const foo&);
foo(const foo&);
public:
friend class FriendClass;
int m_i;
};
int main(int, char*)
{
Widget& MyWidget = Singleton<widget>::Instance();
foo& Myfoo = foo::Instance();
Top ten member of C++ Expert Exchange.
http://www.experts-exchange.com/Cplusplus
|
|
|
|
|
I developed one application which adds the icon to System tray. When I press Start (in menu) it will start.
But in our application ,.->
When I press 'X' in the dialog I don't want to terminate
the application .
When I press Shutdown (which is a menu item when I press on right click on icon )It has to shutdown.
Plz How to handle code in OnSysCommand ., When I press 'X'
in dialog.(Application Should not be terminate.Let it be there itself in the system tray )
Praveen Chowdam Kumar
|
|
|
|
|
|
parims wrote:
Plz How to handle code in OnSysCommand ., When I press 'X'
in dialog.(Application Should not be terminate.Let it be there itself in the system tray )
You have one more option :-
How to remove close button from window?[^]
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
hi all
I have an application that creates a ms word document. I need to include the page number. I have posted a similar question last week but this one is more to the point.
I have done my research and according to msdn, the function to use is
expression.Add(PageNumberAlignment, FirstPage)
WdPageNumberAlignment
constants:
wdAlignPageNumberCenter, wdAlignPageNumberInside, wdAlignPageNumberLeft, wdAlignPageNumberOutside, or wdAlignPageNumberRight
I have no problem calling out the header and footer pop up... navigating between header and footer but I am still unable to add the page number. The above function uses the vb constants. Anyone know the c++ equivalent for these? I tried using it in C++ but its a undeclared identifier.
Thanks in advance.
Thomas
|
|
|
|
|
|
Barm wrote:
Anyone know the c++ equivalent for these?
wdAlignPageNumberLeft = 0
wdAlignPageNumberCenter = 1
wdAlignPageNumberRight = 2
wdAlignPageNumberInside = 3
wdAlignPageNumberOutside = 4
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
I use Visual studio 6, and when I am debugging I can only see character pointers (char *), but for wchar_t pointers I only get the address in the watch/debug windows and I will have to check out the memory explicity. Is there any direct way of seeing the wide char strings during debugging?
thanks
|
|
|
|
|
You can see anything under:
View->Debug Windows->Memory
MS
|
|
|
|
|
Manfred Staiger wrote:
You can see anything under:
View->Debug Windows->Memory
Is that the only way to watch unicode variables? It is too much of work viewing a bunch of variables every time copy/pasting the memory location.
Or atleast, is there a way to open multiple memory windows to watch multiple variables?
|
|
|
|
|
What do you mean ? When I have the following code, I can see "buffer" in the watch window.
wchar_t buffer[25];
memset((void*)buffer, (int)'\0', 25);
memcpy((void*)buffer, _T("Hallo"), sizeof(_T("Hallo")));
MS
|
|
|
|
|
The default symbol for a string is s. Use su instead. There's also st which can be used for ANSI or Unicode depending on what you have in autoexp.dat. These symbols are used in the Watch window after the variable that is being watched.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
I seem to remember that there's an option ( a checkbox) somewhere in the preferences that let you see unicode strings in the debugger.
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
Respected All
Regards
I am a new to VC++.
I have a program that display image(bitmap) selected from listbox while doubled click, but the listbox and image showing in the same window,and when I close the Image window then listbox automatically close.that's I did nothing to show Image in seperate window.
Now i want that listbox window and Image window become seperate and when I want another image from listbox then that listbox window should be there while running once my program.
david
|
|
|
|
|
|
what's that ?
TOXCCT >>> GEII power [toxcct][VisualCalc]
-- modified at 5:02 Monday 12th September, 2005
|
|
|
|
|
How to create multiple instances of IE and submit the form with different clients information and recieve the cookies information for every clients. As the whole process takes three to five round trip to the server for getting and sending information. while trying to solve this problem i am loosing the cookies information and only one user data is propagetted to all the IE instance.
In each round trip i need to recieve four or five cookies from the same server for each client.
Any help or code snippet in this regard.
As i am trying to use the Wininet API.
|
|
|
|
|
hi,
i need to catch DWebBrowserEvents2::NavigateComplete2 event using only win32.
does anyone here know how to do that or know a sample ?
many thanks
|
|
|
|
|
Hi,
In my app::InitInstance()
<br />
{<br />
...<br />
CMyDlg dlg;<br />
m_pMainWnd = &dlg;<br />
dlg.DoModal();<br />
<br />
return TRUE;<br />
}<br />
<br />
The 'CMyDlg' has an internal timer that gets activated after 1 second, and starts executing some actions. After done, the timer is killed and 'CDialog::OnOK' is called. This gets the dialog closed.<br />
<br />
In the app i need to return TRUE, else i got exit code != 0. But now, i get this ennoying warning:<br />
Warning: m_pMainWnd is NULL in CWinApp::Run - quitting application.<br />
<br />
Any way to get this (annoying) warning out of the program?<br />
<br />
Greetings,<br />
Jens
|
|
|
|
|
"Typically, you set this member variable when you override InitInstance. In a worker thread, the value of this data member is inherited from its parent thread."
Can you show the complete code for InitInstance up to dlg.DoModal(); ?
Also, why are you writing to this variable?
The tigress is here
|
|
|
|
|
Dialog based apps must return FALSE from their CWinApp::InitInstance function.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" - mYkel - 21 Jun '04
"There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05
Within you lies the power for good - Use it!
|
|
|
|
|
Hi,
I tried to return false, but then the exit-code of the process is '1'. The exit-code needs to be '0'. I removed the m_pMainWnd = &dlg; line alsoo.
Greetings,
Jens
-- modified at 9:40 Monday 12th September, 2005
|
|
|
|
|
You need to use:
BOOL CMyDialog::InitInstance()
{
return FALSE;
}
int CMyDialog::ExitInstance()
{
return 0;
}
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Hello,
I created a custom scrollbar. I need it to be hidden when the page size is larger than the range.
I used void ScrollBarEx::OnShowWindow(...) fn (mapped) to track the visibility of the scrollbar wnd.
I got the message callback to this fn when the scrollbar wnd is being shown.
But I can't hide the window from fn.
void ScrollBarEx::OnShowWindow(BOOL bShow, UINT nStatus)
{
ShowWindow(SW_HIDE);
}
What steps should I do?
|
|
|
|
|
Hi
Is there any option to check whether the application is launched from startup or normal launch?
Regards
|
|
|
|