|
StackA.h
#ifndef STACKA_H<br />
#define STACKA_H<br />
#include "StackException.h"<br />
#include <new><br />
const int MAX_STACK = 100;<br />
<br />
template < class StackItemType ><br />
<br />
class Stack<br />
{<br />
public:<br />
Stack();
<br />
bool isEmpty() const;<br />
void push(StackItemType newItem) throw(StackException);<br />
void pop() throw(StackException);<br />
void pop(StackItemType& stackTop) throw(StackException);<br />
void getTop(StackItemType& stackTop) const<br />
throw(StackException);<br />
<br />
private:<br />
StackItemType items[MAX_STACK];
int top;
};
<br />
#endif
StackA.cpp
#include "StackA.h"
#include "StackException.h"<br />
<br />
template < class StackItemType ><br />
Stack<StackItemType>::Stack(): top(-1)<br />
{<br />
}
<br />
template < class StackItemType ><br />
bool Stack<StackItemType>::isEmpty() const<br />
{<br />
return top < 0;<br />
}
<br />
template < class StackItemType ><br />
void Stack<StackItemType>::push(StackItemType newItem) throw(StackException)<br />
{<br />
if (top >= MAX_STACK-1)<br />
throw StackException("StackException: stack full on push");<br />
else<br />
{ ++top;<br />
items[top] = newItem;<br />
}
}
<br />
template < class StackItemType ><br />
void Stack<StackItemType>::pop() throw(StackException)<br />
{<br />
if (isEmpty())<br />
throw StackException("StackException: stack empty on pop");<br />
else<br />
--top;
}
<br />
template < class StackItemType ><br />
void Stack<StackItemType>::pop(StackItemType& stackTop) throw(StackException)<br />
{<br />
if (isEmpty())<br />
throw StackException("StackException: stack empty on pop");<br />
else<br />
{
stackTop = items[top];<br />
--top;
}
}
<br />
template < class StackItemType ><br />
void Stack<StackItemType>::getTop(StackItemType& stackTop) const throw(StackException)<br />
{<br />
if (isEmpty())<br />
throw StackException("StackException: stack empty on getTop");<br />
else<br />
stackTop = items[top];<br />
}
in main function of a driver class,
Stack< char > myStack;
The Visual Studio 2005 compiler gives me 6 errors that I cannot understand anything from them.
Here some of them;
Error 22 error LNK2019: unresolved external symbol "public: bool __thiscall Stack<char>::isEmpty(void)const " (?isEmpty@?$Stack@D@@QBE_NXZ) referenced in function "class std::basic_string<char,struct std::char_traits<char="">,class std::allocator<char> > __cdecl convertInfixToPostfix(class std::basic_string<char,struct std::char_traits<char="">,class std::allocator<char> >)" (?convertInfixToPostfix@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@@Z) InfixCalculator
Error 23 error LNK2019: unresolved external symbol "public: void __thiscall Stack<char>::pop(void)" (?pop@?$Stack@D@@QAEXXZ) referenced in function "class std::basic_string<char,struct std::char_traits<char="">,class std::allocator<char> > __cdecl convertInfixToPostfix(class std::basic_string<char,struct std::char_traits<char="">,class std::allocator<char> >)" (?convertInfixToPostfix@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@@Z) InfixCalculator
Error 27 fatal error LNK1120: 5 unresolved externals InfixCalculator
Any help would be appriciated,
Thanks in advance.
|
|
|
|
|
|
All those template functions (in StackA.cpp) used by the templated class must be in the header file not in a seperate CPP file. Otherwise the compiler only has the prototypes for functions it has not generated. Therefore, you will get "unresolved external...", because they do not exist.
INTP
"The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes."
Andrew W. Troelsen
|
|
|
|
|
I've created a MFC Dll, however, when I use the SetTimer function in the Dll, the external application gets error assertions.
Here is my use of the MFC Dll:
DLLClass::void Test()
{
SetTimer(1000, 5000, NULL);
}
DllClass::OnTimer(.....)
{
.....do something when the timer message arrives
}
Here is my external application:
DllClass myclass;
ExtClass::SetMyTimer()
{
myclass.Test;
}
When I call the SetMyTimer function, I got error, how should I do if I want to use SetTimer Function in the MFC Dll?
thanks
|
|
|
|
|
SetTimer() is a method of the CWnd class. Your usage of the function invokes the globally scoped ::SetTimer() Windows API call which takes a window handle as the first argument. Passing a value of "1000" will likely cause abnormal behavior.
You should pass your DLLClass object a valid CWnd (or window handle) which can be passed to the SetTimer() call within Test() .
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Hello,
Does anyone know how to check if the current focus is over certain control, i.e. IDC_EDIT1 or IDC_EDIT2?
Thanks in Advance!
|
|
|
|
|
|
Thank you
|
|
|
|
|
Hi,
I would like to convert a char into an int and vice versa.
For instance;
char a = '3';<br />
int a = 3;
Thanks in advance,
|
|
|
|
|
|
One way would be:
<br />
============================<br />
char chA = '3';<br />
int nA;<br />
char chValue[32];
chValue[0] = chA;<br />
chValue[1] = 0;
nA = atoi(chValue);<br />
============================<br />
char chA;<br />
int nA = 3;<br />
char chValue[32];<br />
itoa(nA, chValue, 10);<br />
chA = chValue[0];<br />
============================<br />
SkyWalker
|
|
|
|
|
Hi Mircea, I used both the array and * implementations and it worked, thank you very much...
Thanks to Dunn also.
|
|
|
|
|
I also would like to ask that is it possible to store for example number 14 in one character array element?
I mean;
if( myCharArray[2] == 14 )<br />
cout << "I want this" << endl;
Thanks,
|
|
|
|
|
if number is only one digit then its simple.
char c = '3';
// char => int
int i = c - '0';
// int => char
c = '0' + i;
|
|
|
|
|
Any source code?
please contact:
max_xiayi@hotmail.com
|
|
|
|
|
Friends,
I've created an application in VC++ 6.0. There is a dialog in it on which i dropped various controls and associate class with that dialog.
Now, i am creating another project in VC++ 6.0. I want to use the same dialog template and its class in this project.
Please tell me how can i "import" dialog from one project to another. Obviously i can reuse class header and cpp, but how can i import dialog template ??
|
|
|
|
|
If you mean the dialog resource, do it this way. Open the old project and simply copy the dialog resource to clipboard. Then, open the new project and paste it into its resource script in the resource view window. Should work.
|
|
|
|
|
unfortunately this is not working in case of different projects. If we have two dialogs in same project then we can copy-paste resources.
|
|
|
|
|
|
Hi All, my CListCtrl's DeleteAllItems() is not working. Although it is returning me non-zero and according to MSDN it returns non-zero when it succeeds but it is not erasing the contents of List control. Any help/advice?
Regards,
Still Alone in this beautiful world
My Articles
|
|
|
|
|
Sorry, I have done it. It was another fault.
Still Alone in this beautiful world
My Articles
|
|
|
|
|
you can send the message LB_RESETCONTENT to the list box
|
|
|
|
|
How to handle the modem connection on the line?
For example i want to call a connection dialog, where i choose the provider of internet (simple connection dialog in windows - how to call it?, i see it when i open the Internet Explorer - it offers me to get online, i want to call such window). Then i want to know - if i connected, so if the connection breaked, i want to handle this situation in my programm - how to do it?
|
|
|
|
|
|
Hello everyone,
I am working on a network program and
I want to lock the desktop and then put
something like a edit box on it.
How can I do that?
Best Wishes.
Thank.
|
|
|
|