我想在我使用的 clang 上為模板化類方法設定回傳型別的別名
template <class R, unsigned int BlockSize>
struct block {
using KeyType = decltype(((R*)nullptr)->getKey());
}
這在 clang 上作業正常,但在 gcc 11.3.0 上我收到警告:
warning: ‘this’ pointer is null [-Wnonnull]
我的問題是在沒有警告的情況下獲取 KeyType 的正確方法是什么?
uj5u.com熱心網友回復:
為了能夠在未評估的背景關系中使用成員函式,例如decltype應該使用的運算式std::declval:
template <class R, unsigned int BlockSize>
struct block {
using KeyType = decltype(std::declval<R>().getKey());
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/534072.html
標籤:C 模板海合会
