静的配列を実装するために書かれた C++ プログラムの意味が知りたい
C++初心者で下記コードを読んでみたところ、以下の通りたくさんの疑問点がありました。お手数をおかけしますがご教示頂けますと幸いです。
- 3行目:
#ifndef LIST
を使う意味について。 - 14行目:
List()
の意味について。とりわけ、()
が何を指すのか。 - 24行目:
bool empty() const
の意味について。とりわけ、const
がなぜempty()
の後ろにあるのか。 - 34行目:
void insert(ElementType item, int pos)
の意味について。とりわけ、なぜvoid
を使うのか。 - 67行目:
void display(ostream & out) const
の意味について。とりわけ、&
が何を示すのか。
#include <iostream>
#ifndef LIST
#define LIST
const int CAPACITY = 1024;
typedef int ElementType;
class List
{
public:
/******** Function Members ********/
/***** Class constructor *****/
List();
/*----------------------------------------------------------------------
Construct a List object.
Precondition: None
Postcondition: An empty List object has been constructed;
mySize is 0.
-----------------------------------------------------------------------*/
/***** empty operation *****/
bool empty() const;
/*----------------------------------------------------------------------
Check if a list is empty.
Precondition: None
Postcondition: true is returned if the list is empty,
false if not.
-----------------------------------------------------------------------*/
/***** insert and erase *****/
void insert(ElementType item, int pos);
/*----------------------------------------------------------------------
Insert a value into the list at a given position.
Precondition: item is the value to be inserted; there is room in
the array (mySize < CAPACITY); and the position satisfies
0 <= pos <= mySize.
Postcondition: item has been inserted into the list at the position
determined by pos (provided there is room and pos is a legal
position).
-----------------------------------------------------------------------*/
void erase(int pos);
/*----------------------------------------------------------------------
Remove a value from the list at a given position.
Precondition: The list is not empty and the position satisfies
0 <= pos < mySize.
Postcondition: element at the position determined by pos has been
removed (provided pos is a legal position).
----------------------------------------------------------------------*/
/***** output *****/
void display(ostream & out) const;
/*----------------------------------------------------------------------
Display a list.
Precondition: out is a reference parameter
Postcondition: The list represented by this List object has been
inserted into ostream out.
-----------------------------------------------------------------------*/
private:
/******** Data Members ********/
int mySize; // current size of list stored in myArray
ElementType myArray[CAPACITY]; // array to store list elements
}; //--- end of List class
//------ Prototype of output operator
ostream & operator<< (ostream & out, const List & aList);
#endif
出典: Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, Figure 6.1A List.h Using Static Array p262~264 © 2005 Pearson Education, Inc. All rights reserved. 0-13-140909-3