|
George_George wrote: I think both declaration and definition can instantise the template function, right?
actually consider declaration, definition implicitly has declaration. if it is inline function, definition should be in the scope at the point of intantiation.
|
|
|
|
|
Thanks Rajkumar,
Your reply is clear. Definition (which is also declaration implicitly) and declaration both will trigger instantiation.
regards,
George
|
|
|
|
|
Hi Rajkumar,
I have a further question. I have tried similar code as yours. But can not compile in Visual Studio 2008. Any ideas? f<int> (100) works. Why?
BTW: a fix of
1>d:\visual studio 2008\projects\test_template3\test_template3\main.cpp(16) : error C2783: 'void f(int)' : could not deduce template argument for 'T'
1> d:\visual studio 2008\projects\test_template3\test_template3\main.cpp(5) : see declaration of 'f'
#include <iostream>
using namespace std;
template <class T> void f(int a) {g (a);}
void g(int a)
{
cout << a << endl;
}
extern void g(double);
int main()
{
f (100);
return 0;
}
regards,
George
|
|
|
|
|
George_George wrote: I have tried similar code as yours
it is not at all similar.
in my example it is
template <class T> void f(T a) {g (a);}
template <class T> void f(int a) {g (a);} in this Template argument T is not addressed, in this case you want call like,
f<char> (100); // i used char just to deduce T.
similarly
template <class T1, class T2> void f(T2 a) {g (a);} here also template argument T1 is not deduced. here also you can use f<char> (100);
if you want template specialization, use like this,
void g(int a)
{ cout << a << endl;
}
extern void g(double);
template <class T>
void f(T a)
{
g (a);
}
<code>template <>
void f(int a)
{
g (a);
}
or
template <>
void f <int>(int a)
{
g (a);
}</code>
int main()
{
f (100);
return 0;
}
modified on Thursday, March 6, 2008 7:20 AM
|
|
|
|
|
Thanks Rajkumar,
I have tried if we remove the following two functions, it still works. Seems the two specializations are useless? Any comments?
template <> void f(int a) { g (a);}
template <> void f <int>(int a) { g (a);}
regards,
George
|
|
|
|
|
that are examples. when i found your examples of "template<class T> void f(int a)", i just given example if you meant specialisation.
George_George wrote: I have tried if we remove the following two functions
because you have generic functions with template argument T already.
George_George wrote: Seems the two specializations are useless?
It is useful if you write special code apart from generic function in the template specialization.
|
|
|
|
|
Thanks Rajkumar!
template <> void f(int a) { g (a);}
template <> void f <int>(int a) { g (a);}
Are the two above function definitons of the same function and just different coding style? Or they have differences?
regards,
George
|
|
|
|
|
I think both are same explicit specialization as if you define both, induce redefinition error, literally, the former template argument is deduced while the later template argument is specified.
|
|
|
|
|
Thanks Rajkumar,
I have got the redefinition error as you pointed out. Cool! But to use the latter one, it is also not mandatory needed to specify the template parameter type, it could also be deduced. Here is my code to prove. Any comments?
#include <iostream>
using namespace std;
void g(int a){ cout << a << endl;}
template <class T> void f(T a) { g (a);}
template <> void f <int>(int a) { g (a);}
int main()
{
f (100);
return 0;
}
regards,
George
|
|
|
|
|
Hello everyone,
As mentioned in Gotw about deque. What means "streamlined version of deque with simplified iterators"? I did some search and can not find out.
http://www.gotw.ca/gotw/054.htm
--------------------
Finally, note that the popular library implementation that I tested has since been revised and now includes a streamlined version of deque with simplified iterators. I do not yet have a copy of that library, but it will be interesting to see how much of the deque disadvantage in even the raw iterator "traverse" and element-accessing "at" tests will remain compared to vector.
--------------------
thanks in advance,
George
|
|
|
|
|
it simply means there is a STL library somewhere that even Sutter does not yet have (at the time of the writing) contains a streamline version of the dequeue container and simplified iterator.
streamline means better (either in performance and/or in memory useage).
simplified means, well, more simple than the current implementation (I assume the current one is not simple)
I also assume that you know that the "Guru Of The Week" #54 is nearly 19 years old (written in 1999) and that there have been lots of improvements in STL and that what he was writing about is probably already included in the current STL implementation and that there are no "non" streamline or "non" simplified versions of dequeue.
you could try to get a copy of the dequeue code from that time and compare it with the current code to see what have changed.
|
|
|
|
|
Thanks Maximilien!
1.
What is your point? The Gotw #54 is out of date?
2.
I want to learn your comments about what do you think are possible improvements? compare with traditional implementation of deque? Currently, I only know traditional way of implementing deque -- chunks and chunks containing elements.
regards,
George
|
|
|
|
|
Hi,
I just want to ask how can i select folder in file open dialog?
Because it usually enters a folder when i select it.
Is it possible?
If not what should i use and how will i do it?
Thank you.
|
|
|
|
|
|
You can do this by adding another button to the dialog template ([Select] for example), and when clicked you can return the path(s) to the selected item(s).
Lookup customizing the common file dialog for more information on how to specify a custom dialog template and react to actions taken in it.
Peace!
-=- James Please rate this message - let me know if I helped or not!<hr></hr> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
Hello friends,
Please find the following code that creates the problem in release mode and run well in debug mode.I am using VC 6.0.
<
#include "win.h"//this file contains the declarations of the classes
#define ID_TIMER1 1
BEGIN_MESSAGE_MAP(MyWin,CFrameWnd)
END_MESSAGE_MAP()
MyWin::MyWin()
{
Create(NULL,"Test");
}
BEGIN_MESSAGE_MAP(App,CWinApp)
ON_WM_TIMER()
END_MESSAGE_MAP()
BOOL App::InitInstance()
{
m_pMywin=new MyWin();
m_pMainWnd=m_pMywin;
m_pMainWnd->UpdateWindow();
m_pMainWnd->ShowWindow(SW_SHOWNORMAL);
::SetTimer(NULL,ID_TIMER1,5000,NULL);
return TRUE;
}
void App::OnTimer()
{
AfxMessageBox("App Timer");
}
App obj;
>
ritz1234
|
|
|
|
|
First of all: debug your application!
This is essential if you want help from others. You will be asked questions about the results from your debugging sessions and if you cannot answer those questions, you cannot be helped. An explanation like "it crashes" is always wrong unless followed by an explanation about how it crashes.
More on the problem:
In my opinion you're using the timer API in an unusual way by having the application class handle the WM_TIMER message. Having your window class setting up the timer and handle its events would be more straight forward. I'm not saying that it's impossible, because it's not, but if you're less experienced with MFC and message handling you'd be better off by choosing a main stream solution.
You should also read the documentation carefully; calling ::SetTimer() with the hWnd param set to NULL makes the function return the ID of the timer. It could be a new ID that you're supposed to use when calling ::KillTimer(), but you simply ignore it.
You also have to verify that the problem actually is related to the timer. In your previous thread you mention something about multiple threads and a web cam that may also have something to do with this.
Now I'm just guessing, but it could be a plausible cause: you have an ActiveX control that receives input from the web cam and you're trying to access it from another thread than the one that created the control without proper marshalling.
To help you further, whether it would be me or anyone else, you have to debug your application and tell us how it fails.
If you're only having troubles in the release version, then build the release version with debug info. There are more differences between building release mode and debug mode than just creating the debug info.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Hi,thanx for the reply,
Right now forgot about the previous posts.
This is the sample test application which also fails believe me.
If you want then try it out.
It crashes in release mode as following.
When I run the application in release mode the OnTimer function gets
executed and then after it crashes with dialog to send the error report
to microsoft with the "send" and "Don't send" buttons.
The win.h file on the above code snippest has the following code
class MyWin:public CFrameWnd
{
public:
MyWin();
DECLARE_MESSAGE_MAP()
};
class App:public CWinApp
{
public:
MyWin *m_pMywin;
BOOL InitInstance();
afx_msg void OnTimer();
DECLARE_MESSAGE_MAP()
};
ritz1234
|
|
|
|
|
I copied your code to make a SDI project with VC++ 2005. There are some issues.
First of all, the prototype of OnTimer is not what you wrote. The correct one is:
afx_msg void CWnd::OnTimer(UINT_PTR nID);
OnTimer is a member function of CWnd . And Your App class is of the base CWinApp , which is not CWnd .
And Secondly, your this line doesn't compile at all.
BEGIN_MESSAGE_MAP(App, CWinApp)
ON_WM_TIMER()
END_MESSAGE_MAP()
The reason is as mentioned above: OnTimer is a member function of CWnd , not of CWinApp . Therefore static_cast is not allowed.
Maxwell Chen
|
|
|
|
|
Ok, in other words:
You have a serious design flaw in your application. You're using the SDK version of SetTimer() since SetTimer() is not defined in CWinApp . When using MFC you would usually do this in a CWnd derived class since SetTimer() is defined in the CWnd class.
Using the ON_WM_TIMER macro is very wrong in your case, since it assumes the class to be a CWnd subclass and you're using it from a CWinApp subclass. On top of that the message handler you provide as a parameter to ON_WM_TIMER must be declared as
afx_msg void OnTimer( UINT nIDEvent ); . You have omitted the parameter which will, at the best, corrupt the stack frame.
Like I wrote earlier, it's possible to use a timer in the app class, but chances that this is really what you want to do are ridiculously close to zero depending on how the MFC framework is intended to be used.
I recommend you to stay within the MFC classes for doing basic stuff like this.
If you want to start the timer when the application start, you should declare a message handler for the WM_CREATE message and override the CWnd::OnCreate() member function. From your message handler you can call CWnd::SetTimer() . Use the wizards for this and don't forget to add a message handler for WM_TIMER as well and override CWnd::OnTimer() .
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Hi, thanx Roger and Maxwell.
I also realize that I should not use the timer for the application class
because they can be used by the CWnd derieved class. So I change the code
of the application and I use timer in class derieved from CMDIFrameWnd.
So the problem is solved now.
Thanks for the help once again.
ritz1234
|
|
|
|
|
I need to write a text line vertically and at the same time the font must have every char displayed with the same width (like courier , or like the font used in VS editor to let us move vertically along the columns) (hope be clear).
Now:
If I use Courier Font I get the right font...but it seems uncompatible with the nEscapement parameter to write the text vertically.
If I use Tahoma the nEscapement parameter is well imported, but the space between the char is not constant.
So
How can I find a font that let me use both this properties?...Is there some property that I can check?
Of course...only using the standard fonts that Windows user has got by default.
Thanks a lot
Russell
|
|
|
|
|
Not sure, But why not let the CreateFont() pick the font which matches the characteristics?
|
|
|
|
|
I am using CreateFont....but not every font type understand the Escapement parameter...I'm trying every font right now... I'm going crazy
Russell
|
|
|
|
|
Russell' wrote: I'm trying every font right now
I think you are setting the font name in the "lpszFace"
"If lpszFace is NULL or empty string, GDI uses the first font that matches the other specified attributes" from msdn.
|
|
|
|