Skip to content

Commit

Permalink
C++17 インライン変数 : 異なる型でインライン指定してはならないことはすでに仕様として書いてあったので、例示という形で無名クラスオブ…
Browse files Browse the repository at this point in the history
…ジェクトの解説をするよう修正

e68299b#comments
  • Loading branch information
faithandbrave committed Jan 3, 2023
1 parent 994ee06 commit 651153b
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions lang/cpp17/inline_variables.md
Expand Up @@ -47,6 +47,24 @@ extern inline int a;

`inline`指定した同名の変数は全て同じ定義にすべきである。翻訳単位によって異なる型、初期値で変数を定義すると、プログラムは正常に動作しない可能性がある (不適格(例外付き診断不要))。

異なる型を指定した場合の例:

```cpp
// b.cpp
// 無名クラスのオブジェクトはそれぞれ異なる型となる
inline struct { int x; } y;

// a.cpp
// 不適格 (診断不要)
// コンパイルエラーにならないかもしれないが、正常に動作しない可能性がある
// (実装によっては、それぞれ異なる実体のオブジェクトとなる場合がある)
inline struct { int x; } y;

int main() {}
```
異なる初期値を指定した場合の例:
```cpp
// b.cpp
inline int hoge = 10;
Expand Down Expand Up @@ -94,9 +112,6 @@ function-specifier:
explicit
```

## 備考
- 名前のないクラスのオブジェクトは、インライン指定しても同じ実体にはならない


##

Expand Down

0 comments on commit 651153b

Please sign in to comment.