相关疑难解决方法(0)

有没有办法在C++函数中获取函数名?

我想实现一个函数跟踪器,它将跟踪一个函数执行的时间.我有以下课程: -

class FuncTracer
{
    public:
        FuncTracer(LPCTSTR strFuncName_in)
        {
            m_strFuncName[0] = _T('\0');
            if( strFuncName_in ||
                _T('\0') != strFuncName_in[0])
            {   
                _tcscpy(m_strFuncName,strFuncName_in);

                TCHAR strLog[MAX_PATH];
                _stprintf(strLog,_T("Entering Func:- <%s>"),m_strFuncName);
                LOG(strLog)

                m_dwEnterTime = GetTickCount();
            }
        }

        ~FuncTracer()
        {
            TCHAR strLog[MAX_PATH];
            _stprintf(strLog,_T("Leaving Func:- <%s>, Time inside the func <%d> ms"),m_strFuncName, GetTickCount()-m_dwEnterTime);
            LOG(strLog)
        }

    private:
        TCHAR m_strFuncName[MAX_PATH];
        DWORD m_dwEnterTime;
};

void TestClass::TestFunction()
{
    // I want to avoid writing the function name maually..
    // Is there any macro (__LINE__)or some other way to 
    // get the function …
Run Code Online (Sandbox Code Playgroud)

c++ macros profiling

26
推荐指数
3
解决办法
4万
查看次数

C++使用标头定义的模板类使用Multiply定义的符号

我正在使用Visual Studio 2005中的DLL和EXE项目.在DLL的代码中,有一个可扩展数组类的模板:

template <class Type>
class GArray
{
    Type *p;
    uint32 len;
    uint32 alloc;

protected:
    bool fixed;

public:
    /// Constructor
    GArray(int PreAlloc = 0)
    {
        p = 0;
        len = 0;
        fixed = false;

        alloc = PreAlloc;
        if (alloc)
        {
            int Bytes = sizeof(Type) * alloc;
            p = (Type*) malloc(Bytes);
            if (p)
            {
                memset(p, 0, Bytes);
            }
            else
            {
                alloc = 0;
            }
        }
    }

    /// Destructor  
    ~GArray()
    {
        Length(0);
    }   

    /// Returns the number of used entries
    uint32 …
Run Code Online (Sandbox Code Playgroud)

c++ templates visual-studio-2005

5
推荐指数
1
解决办法
5645
查看次数

标签 统计

c++ ×2

macros ×1

profiling ×1

templates ×1

visual-studio-2005 ×1