Click here to Skip to main content
15,916,019 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: DLL Question Pin
ThatsAlok2-Mar-07 0:20
ThatsAlok2-Mar-07 0:20 
QuestionRe: DLL Question Pin
Programm3r2-Mar-07 0:37
Programm3r2-Mar-07 0:37 
QuestionIE control painting issue. - Urgent. Pin
Suyash1-Mar-07 23:01
Suyash1-Mar-07 23:01 
AnswerRe: IE control painting issue. - Urgent. Pin
Mark Salsbery2-Mar-07 9:00
Mark Salsbery2-Mar-07 9:00 
QuestionFile pointer & File descriptor Pin
san123pune1-Mar-07 22:55
san123pune1-Mar-07 22:55 
AnswerRe: File pointer & File descriptor [modified] Pin
toxcct1-Mar-07 22:58
toxcct1-Mar-07 22:58 
GeneralRe: File pointer & File descriptor Pin
san123pune1-Mar-07 23:13
san123pune1-Mar-07 23:13 
QuestionTemplate Class Problem - Newbie [modified] Pin
antonaras1-Mar-07 22:35
antonaras1-Mar-07 22:35 
Hi guys

I'm trying to figure out how to make a template class History. This class should be able to record history moves.(for any application). e.g. a history of changed in an editor, or a history of URLs in a web browser etc.

This is what i came up with so far.
<br />
#include < stack ><br />
#include < iostream ><br />
#include < string ><br />
<br />
using namespace std;<br />
<br />
template < typename E > <br />
class history<br />
{<br />
	private:<br />
                //i'm using to stacks to record history<br />
		stack < E > back_list; <br />
		stack < E > forward_list;<br />
<br />
	public:<br />
		history();<br />
		void add_entry(const E & entry);<br />
		E & undo();<br />
		E & redo();<br />
		bool no_undo();<br />
		bool no_redo();<br />
};<br />
<br />
template < typename E ><br />
void history < E >::add_entry(const E & entry)<br />
{<br />
	back_list.push(entry);<br />
	while(!forward_list.empty())<br />
	{<br />
		forward_list.pop();<br />
		<br />
	}<br />
}<br />
<br />
template < typename E > <br />
E & history < E >::undo()<br />
{<br />
	E entry;<br />
	if(!back_list.empty())<br />
	{<br />
		entry = back_list.top();<br />
		back_list.pop();<br />
		forward_list.push(entry);<br />
		<br />
	}<br />
<br />
	return(entry);<br />
}<br />
<br />
template < typename E > <br />
E & history < E >::redo()<br />
{<br />
	E entry;<br />
	if(!forward_list.empty())<br />
	{<br />
		entry = forward_list.top();<br />
		forward_list.pop();<br />
		back_list.push(entry);<br />
	}<br />
	return(entry);<br />
}<br />
<br />
template < typename E > <br />
bool history < E >::no_undo()<br />
{<br />
	if(back_list.empty())<br />
		return(1);<br />
	else return (0);<br />
}<br />
<br />
template < typename E > <br />
bool history < E >::no_redo()<br />
{<br />
	if(forward_list.empty())<br />
		return (1);<br />
	else return (0);<br />
}<br />
<br />
<br />
<br />
void main()<br />
{<br />
	history <int> his;<br />
	his.add_entry(2);<br />
	int out;<br />
	out = his.undo();<br />
	cout<<out;<br />
	<br />
}<br />
<br />

I get no compilation errors but as soon as i try to run it i get:
<br />
Linking...<br />
history.obj : error LNK2001: unresolved external symbol "public: __thiscall history<int>::history<int>(void)" (??0?$history@H@@QAE@XZ)<br />
Debug/history.exe : fatal error LNK1120: 1 unresolved externals<br />
Error executing link.exe.<br />
<br />
history.exe - 2 error(s), 0 warning(s)<br />


Any ideas of i'm doing wrong?
It's the first time i'm using template so i'll appreciate any help.

Thank in advance.






-- modified at 4:43 Friday 2nd March, 2007
AnswerRe: Template Class Problem - Newbie Pin
toxcct1-Mar-07 22:39
toxcct1-Mar-07 22:39 
GeneralRe: Template Class Problem - Newbie Pin
antonaras1-Mar-07 22:47
antonaras1-Mar-07 22:47 
GeneralRe: Template Class Problem - Newbie Pin
toxcct1-Mar-07 22:53
toxcct1-Mar-07 22:53 
AnswerRe: Template Class Problem - Newbie Pin
prasad_som1-Mar-07 22:47
prasad_som1-Mar-07 22:47 
GeneralRe: Template Class Problem - Newbie Pin
antonaras1-Mar-07 22:57
antonaras1-Mar-07 22:57 
QuestionHow to put combo box as list subitem? Pin
Aryan S1-Mar-07 21:48
Aryan S1-Mar-07 21:48 
AnswerRe: How to put combo box as list subitem? Pin
prasad_som1-Mar-07 22:02
prasad_som1-Mar-07 22:02 
AnswerRe: How to put combo box as list subitem? Pin
Hamid_RT1-Mar-07 23:41
Hamid_RT1-Mar-07 23:41 
Questioncommunication program Pin
Kiethnt1-Mar-07 21:27
Kiethnt1-Mar-07 21:27 
QuestionComboBox Height Pin
Nishad S1-Mar-07 21:21
Nishad S1-Mar-07 21:21 
AnswerRe: ComboBox Height Pin
prasad_som1-Mar-07 21:48
prasad_som1-Mar-07 21:48 
GeneralRe: ComboBox Height Pin
Nishad S1-Mar-07 21:51
Nishad S1-Mar-07 21:51 
AnswerRe: ComboBox Height Pin
prasad_som1-Mar-07 21:57
prasad_som1-Mar-07 21:57 
GeneralRe: ComboBox Height Pin
Nishad S1-Mar-07 22:31
Nishad S1-Mar-07 22:31 
AnswerRe: ComboBox Height Pin
prasad_som1-Mar-07 22:42
prasad_som1-Mar-07 22:42 
GeneralRe: ComboBox Height Pin
Nishad S1-Mar-07 22:50
Nishad S1-Mar-07 22:50 
QuestionRe: ComboBox Height Pin
prasad_som1-Mar-07 23:04
prasad_som1-Mar-07 23:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.