|
Aha! You didn't respect the requirements either: "then add a reasonable set of unit tests, with output, to main.cpp" If you move your main to a different CPP file you will run into errors.
The other thing I don't understand is why you mix the "T" and "t".
Otherwise your implementation is almost exactly like mine. In the invert function, I like my variable names (prev, crt, next) a bit more than yours but this is such a stylistic detail that I'm not going to argue about. I did mention it however because I'm a bit anal (Some people would call me an anal a..hole but that's a bit pleonastic, isn't it?).
Mircea
|
|
|
|
|
Mircea Neacsu wrote: add a reasonable set of unit tests, with output, to main.cpp" Ah you caught me, I will try that sometime and let you know how it goes.
I did not mix "T" and "t", they are set like that in the header file. So I found a way to implement the code without changing them. As I said earlier, I would not do it this way if I had the choice.
Mircea Neacsu wrote: I like my variable names (prev, crt, next) I have to admit it took me a few goes to get that right, hence the names which (at the time) seemed most reasonable.
Mircea Neacsu wrote: a bit pleonastic I am embarrassed to admit that I had to check my dictionary for "pleonasm". I had assumed you are Romanian, but your bio says Canadian; that makes me feel a bit better.
|
|
|
|
|
Quote: I had assumed you are Romanian, but your bio says Canadian; that makes me feel a bit better.
I am Romanian but I've called Canada home for many years now. Too bad my accent is not as good as my vocabulary
Mircea
|
|
|
|
|
Canada has long been a favourite place although I have not spent nearly enough time there. My brother lives in Toronto, about 10 minutes drive from CodeProject HQ (according to Google). Visited there in 2008 for a wedding, and also went up to Manitoulin island to stay with an aunt for a few days. I visited Vancouver a number of times in the 60s while working on a merchant ship. Went back in 2014 for another wedding, and was reminded why I love that city and its environs. Sadly it's a bit late to think about emigrating, and all my, and my wife's, immediate family are close at hand here.
|
|
|
|
|
Yes, both Toronto and Vancouver are beautiful places. I live in Montreal that used to be a wondrous place before this COVID thing. If you ever come visit, I'd bet you will enjoy it.
Cheers,
Mircea
|
|
|
|
|
Mircea Neacsu wrote: If you move your main to a different CPP file you will run into errors. But not too difficult to fix with a little thought. The problem is that the implementation in stack.cpp is still a bunch of templates, so when compiled it does not generate any code. I discovered this by generating the assembly listing. So I added the following dummy function to stack.cpp which instantiates one of every template function and it compiles and links cleanly.
void sample()
{
stack<T> dummy;
dummy.push("A");
dummy.size();
dummy.top();
dummy.pop();
dummy.invert();
}
Oh, and I missed the part in the original which said "do not amend stack.h unless you see any mistakes". The mistake of course was all those lower case 't's in the templates. Changing them to upper case fixes it.
So my take home is that I learned a few useful things, including how not to use templates. But I think the test was valid as it is a good challenge for the candidate. Had he got it right it would probably have created an opportunity to discuss the whole thing with the people who devised the test. I don't think they are as dumb as first appears.
|
|
|
|
|
Richard MacCutchan wrote: I don't think they are as dumb as first appears.
You are too generous. Me, the eternal optimist, at the question "Can people be that dumb?" I always answer "Yes! they can!"
|
|
|
|
|
Mircea Neacsu wrote: template <class t=""> struct _node The ="" characters are not really there. The CodeProject editor mistranslates tab characters in some instances.
|
|
|
|
|
Tim, I am close to a working solution but there are still a couple of loose ends to tie up. Do you have the original copies of the stack.h and CMakeLists.txt files that you could post here?
|
|
|
|
|
What does QueryPerformanceFrequency measure? units per second?
|
|
|
|
|
Here's how I get the current time (in ticks):
TimePoint SysTickTimer::Now() const
{
if(available_)
{
LARGE_INTEGER now;
QueryPerformanceCounter(&now);
return TimePoint(now.QuadPart);
}
else
{
_timeb now;
_ftime_s(&now);
auto msecs = 1000LL * now.time;
return TimePoint(msecs + now.millitm);
}
}
My Windows 10 installation, running on a Dell XPS15, has 10^7 ticks per second (1 tick = 0.1 usecs). This is determined by
LARGE_INTEGER frequency;
if(QueryPerformanceFrequency(&frequency))
{
available_ = true;
ticks_per_sec_ = frequency.QuadPart;
}
|
|
|
|
|
it`s ticks per second. Thanks Greg for showing how you handle it.
|
|
|
|
|
|
thanks, I got it working.
|
|
|
|
|
Can anyone help me in my C++ course?
|
|
|
|
|
|
|
Are you female and cute?
Just kidding, but when I was back in engineering school a *very* long time ago, that never hurt.
Charlie Gilley
<italic>Stuck in a dysfunctional matrix from which I must escape...
"Where liberty dwells, there is my country." B. Franklin, 1783
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
|
|
|
|
|
I have a CDialog derived dialog which has a CFormView derived member which has a number of CEdit derived controls placed on it.
Based on business rules at runtime one of the CEdit derived controls should receive the focus when the dialog is displayed. In the OnInitialUpdate override of the CFormView derived class the specfic control is determined and focus is set to that control with the following call:
PostMessage(WM_NEXTDLGCTL, (WPARAM)pFocusEdit->GetSafeHwnd(), TRUE);
When the dialog is displayed there is no caret displayed within the control. It is outlined in the blue colour showing that it has focus, if I start typing the text is displayed but still no caret. If I TAB to the next control the caret is displayed there and if I TAB back it is now displayed in the originally focused control.
Alternatively, after the dialog is initially displayed and the caret is not showing If I shift the active window to another app (e.g. visual studio) and then actiavte the app again then the caret does appear in the CEdit control.
Any suggestions as to how I can ensure that the desired CEdit control receives focus on display of the dialog and that the caret is displayed?
Thanks,
|
|
|
|
|
|
Richard MacCutchan wrote: You should use the OnInitDialog method of CDialog Class | Microsoft Docs[^] to set the focus.
I stated that the focus edit is being set from the OnInitialUpdate override of the CFormView derived class, I should have clarified that this has been called from the CDialog OnInitDialog method via a call to
SendMessageToDescendants(WM_INITIALUPDATE, 0, 0, TRUE, TRUE);
Also, the OnInitDialog method returns FALSE to indicate that I have set the focus to a control.
.
|
|
|
|
|
Sorry, I cannot help further as I don't have MFC.
|
|
|
|
|
Is it possible to somehow check during compile time if an enum exists, i.e. something like this:
typedef enum {
MY_ENUM_VALUE = 0
} myEnum_e;
#define DOES_ENUM_EXIT(__ARG__) ??? What goes here???
if (DOES_ENUM_EXIT(myEnum)) {
} I know that I could achieve something similar easily be using
#define MY_ENUM_VALUE (0)
instead, but then my code wouldn't be type safe.
|
|
|
|
|
|
No, because the #define statement is handled by the preprocessor, and the enum value is not known until it is fed into the compiler, which comes later.
|
|
|
|