簡體   English   中英

如何在編譯時檢測類的聲明?

[英]How to detect declaration of class at compile-time?

我在我的項目中使用了一些 3-rd 方庫。 更新到新版本的庫后,我遇到了錯誤。

一個我的班級有方法

virtual RTSPServer::RTSPClientSession* createNewClientSession(u_int32_t sessionId)override;

但是在新版本的 RTSPClientSession 庫聲明中被移到另一個類中並重命名。 現在正確的名字是

GenericMediaServer::ClientSession

我需要一個可以與所有版本的庫正確編譯的代碼。

在 gcc 我使用以下代碼:

#ifdef RTSPServer::RTSPClientSession
    using ClientSessionClass = RTSPServer::RTSPClientSession;
#else
    using ClientSessionClass = GenericMediaServer::ClientSession;
#endif

class A
{
    .........
    virtual ClientSessionClass* createNewClientSession(u_int32_t sessionId)override;
};

但這在 MSVC 2010 中不起作用。如何檢測我應該使用哪個聲明?

UPD:gcc 的代碼也不適用於舊版本的庫:(

“我如何檢測我應該使用哪個聲明?”

您需要為當前構建配置使用的庫版本引入一些鑒別器:

#ifdef OLD_LIBRARY_VERSION // Maybe the binding headers have some information like this.
                           // If not you have to select this manually, and provide the 
                           // setting with your project configuration.
   using ClientSessionClass = RTSPServer::RTSPClientSession;
#else
   using ClientSessionClass = GenericMediaServer::ClientSession;
#endif

暫無
暫無

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

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