第9章メモリモデルと名称空間の練習問題
a.自動変数b.secretを1つのファイルで外部変数として定義し、2番目のファイルでexternを使用して宣言する必要があります.c.外部定義の前にキーワードstaticを付け、topsecretを内部リンクのある静的変数として定義したり、名前のない名前空間で定義したりすることができます.d.関数の宣言の前にキーワードstaticを付け、beencalledをローカル静的変数として定義します.
USing宣言:using名前空間名::名前例:using Jill::fetch;//これはusing声明です.usingコンパイル命令:using namespace名前空間名例:using namespace Jill;//これはusingコンパイル命令です
#include
int main()
{
double x;
std::cout << "Eneter value: ";
while(!(std::cin >> x))
{
std::cout << "Bad input. Please enter a number: ";
std::cin.clear();
while(std::cin.get()!='
')
continue;
}
std::cout << "Value = " << x << std::endl;
return 0;
}
#include
int main()
{
using std::cout;
using std::cin;
using std::endl;
double x;
cout << "Eneter value: ";
while(!(cin >> x))
{
cout << "Bad input. Please enter a number: ";
cin.clear();
while(cin.get()!='
')
continue;
}
cout << "Value = " << x << endl;
return 0;
}
各ファイルに個別の静的関数定義を含めることができます.または、各ファイルは、名前のない名前空間で適切なaverage()関数を定義します.
10
4
0
Other: 1011296-1
another(): 10, -4
1
4, 1, 2
2
2
4, 1, 2
2