【发布时间】:2010-10-05 02:11:33
【问题描述】:
我用 C++ 编写了一个文本编辑器程序,它具有简单的命令:LEFT、RIGHT、HOME、END、BACKSPACE、DELETE、INSERT,现在我需要执行 UNDO 和 REDO 功能。在我的程序中,用户必须能够撤消不超过最后十个命令。我想使用矢量实现来实现这一点,但我不知道如何设置它。我不确定如何将光标位置和字符存储到向量中。有人可以提供帮助吗?
#ifndef CURSOR_H
#define CURSOR_H
#include <stdlib.h>
#include <iostream>
template <class Object>
class Cursor;
// Incomplete Declaration
template <class Object>
class CNode
{
public:
CNode( const Object & theElement = Object( ), CNode * n = NULL ) : element( theElement ), next( n ) { }
Object element;
CNode *next;
friend class Cursor<Object>;
};
template <class Object>
class Cursor
{
public:
Cursor( );
bool isEmpty( ) const;
void makeEmpty( );
void left ( );
void right ( );
void del ( ); //This is the delete operation. I named it del instead of delete as delete conflicts with a C++ keyword.
void back ( );
void insert( const Object & x );
void home ( );
void end ( );
void undo ( );
private:
void printText ( ) ;
CNode<Object> *header;
CNode<Object> *cursorPosition;
};
//#include "Cursor.cpp"
#endif
【问题讨论】:
标签: c++