考慮一個static constexpr
成員的這種使用情況:將靜態const成員重新聲明爲constexpr會自動使其成爲內聯嗎?
// smart_enum.h
class smart_enum {
// Some data, operations, etc.
// Cannot use constexpr here, smart_enum is incomplete at this point
static const smart_enum first, second;
};
constexpr smart_enum smart_enum::first = {}, smart_enum::second = {};
是first
和second
自動inline
變量?還是我需要對其進行限定?或者我無法將它們限定爲內聯,並且稍後需要在某個源文件中提供定義?我一直很困惑,從const
到constexpr
這個「重新定義」,並希望更多的光芒流失這意味着什麼。
具體來說,我想知道關於const
聲明constexpr
定義,以及如何與一個static constexpr
(Redefinitions of constexpr static data members are allowed now? (but not inline const)?)
「此外,constexpr說明符暗示靜態數據成員以及函數的內聯。」 - 但是我想把這個constexpr放在課堂上。 – lorro
@lorro,但你不能把它放在課堂上,這是我的困惑所在。 – user975989