Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
654c879
commit 2114ad7
Showing
3 changed files
with
25 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# 抽象型のチェック | ||
* cpp20[meta cpp] | ||
|
||
## 概要 | ||
C++17までは以下の仕様があったため、抽象クラスに早期の制限があった: | ||
|
||
> 抽象クラスは、パラメータ型、関数の戻り値型、明示的型変換の型として使用してはならない。抽象クラスへのポインタや参照は宣言できる。 | ||
しかし、先行宣言したクラスは、あとで定義が追加されるために、パラメータ型、関数の戻り値型、明示的型変換の型として使用できる。 | ||
|
||
``` | ||
struct S; | ||
S f(); // OK: 抽象性はここではチェックされない | ||
struct S { virtual void f() = 0; }; | ||
S f(); // エラー!抽象クラスは関数の戻り値型として使用できない | ||
``` | ||
|
||
C++20ではこれを適格とし、先行宣言と同様にクラスの完全性のチェックは、定義と呼び出しまで先送りすることとする。 | ||
|
||
|
||
## 参照 | ||
- [P0929R2 Checking for abstract class types](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0929r2.html) |