5-8

3466 ワード

 1 #include <iostream>
 2 
 3 using namespace std;
 4 
 5 class A
 6 {
 7 public:
 8     A(int i);
 9     void print();
10 private:
11     const int a;
12     static const int b=10;
13 };
14 
15 
16 A::A(int i):a(i){}
17 
18 void A::print()
19 {
20     cout<<a<<":"<<b<<endl;
21 }
22 // 
23 
24 int main()
25 {
26     A a1(100),a2(0);
27     a1.print();
28     a2.print();
29 
30     return 0;
31 }