在Java 中,如果产生异常,程序员可以很方便地调用printStackTrace()显示堆栈情况,这是因为Java虚拟机掌握所有运行时系统的信息。但是在C++中就没有相应的功能了,为了方便在调试时观察堆栈调用情况,我写了个很简单的框架来实现基本功能。
#include
<
string
>
#include < list >
#include < exception >
#include < iostream >
using std::cout;
using std::endl;
/**/ /**
* Calling stack recording class, used to store function names in current
* calling stack.
*
* @see Tracelet
*/
class StackRecord
... {
public:
static void PrintStack();
static void Push(const std::string& aFuncName);
static void Pop();
private:
static std::list<std::string> mNames;
} ;
#include < list >
#include < exception >
#include < iostream >
using std::cout;
using std::endl;
/**/ /**
* Calling stack recording class, used to store function names in current
* calling stack.
*
* @see Tracelet
*/
class StackRecord
... {
public:
static void PrintStack();
static void Push(const std::string& aFuncName);
static void Pop();
private:
static std::list<std::string> mNames;
} ;