簡體   English   中英

這在C ++中的函數參數中是什么意思

[英]what does this # mean in function parameter in C++

template<typename Mutex>
class CMutexLock
{

public:
    CMutexLock(Mutex& mutexIn, const char* pszName, const char* pszFile, int nLine, bool fTry = false) : lock(mutexIn, boost::defer_lock)
    {
        if (fTry)
            TryEnter(pszName, pszFile, nLine);
        else
            Enter(pszName, pszFile, nLine);
    }
};

typedef CMutexLock<CCriticalSection> CCriticalBlock;    
#define LOCK(cs) CCriticalBlock criticalblock(cs, #cs, __FILE__, __LINE__)

我正在學習開源代碼,並且想知道#cs中的#是#cs意思,並且如果可能的話,它在該代碼中做什么? 它用於#define LOCK(cs) CCriticalBlock criticalblock(cs, #cs, __FILE__, __LINE__)它是從CMutexLock模板定義LOCK(cs)來構造CMutexLock類的,它在CMutexClass構造函數上正在接收指針的第二個參數上終止為空

#define宏中,符號前的#表示要“符號化”該符號,這意味着繼續使用該符號的符號會被加引號。

因此,例如給出以下宏:

#define STR(x) #x

像這樣使用:

char *p = STR(hello);

被替換為:

char *p = "hello";

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM