Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

22.2節の文脈を考慮した修正PR #160

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions 022-implement-array.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,27 +180,28 @@ struct array_int_10
配列はコピーできないが、クラスのデータメンバーとして宣言した配列は、クラスのコピーの際に、その対応する順番の要素がそれぞれコピーされる。

~~~cpp
struct array_int_3 { int storage [3] ; } ;
struct array_int_10 { int storage [10] ; } ;

int main()
{
array_int_3 a = { 0,1,2 } ;
array_int_10 a = {0,1,2,3,4,5,6,7,8,9} ;

array_int_3 b = a ;
array_int_10 b = a ;
// b.storage[0] == a.storage[0]
// b.storage[1] == a.storage[1]
// b.storage[2] == a.storage[2]
// ...
}
~~~

これはあたかも以下のように書いたかのように動く。

~~~cpp
struct array_int_3
struct array_int_10
{
int storage[3] ;
int storage[10] ;

array_int_3( array_int_3 const & other )
array_int_10( array_int_10 const & other )
{
std::copy(
std::begin(other.storage), std::end(other.storage),
Expand Down Expand Up @@ -228,7 +229,7 @@ int main()
{
array_int_10 a = {0,1,2,3,4,5,6,7,8,9} ;
a[3] = 0 ;
std::cout << a[6] ;
std::cout << a[3] ;
}
~~~

Expand Down