#5
by かずま » 6年前
遊び人 さんが書きました:ちなみにc++11以前はどうしていたのでしょうか?
for文でもできますが、<algorithm> の fill を使ってもよいでしょう。
コード:
#include <iostream>
#include <algorithm>
using namespace std;
class A {
private:
int test[10];
public:
A() { fill(test, test+10, 0); } //コントラスタ
int give_a(int num) const { return test[num]; }
};
int main()
{
A a;
for (int i = 0; i < 10; i++) {
cout << a.give_a(i) << endl;
}
return 0;
}
[quote="遊び人" id=3,19582,147899]ちなみにc++11以前はどうしていたのでしょうか?[/quote]
for文でもできますが、<algorithm> の fill を使ってもよいでしょう。
[code]
#include <iostream>
#include <algorithm>
using namespace std;
class A {
private:
int test[10];
public:
A() { fill(test, test+10, 0); } //コントラスタ
int give_a(int num) const { return test[num]; }
};
int main()
{
A a;
for (int i = 0; i < 10; i++) {
cout << a.give_a(i) << endl;
}
return 0;
}
[/code]