作者在 2010-07-02 20:11:37 发布以下内容
#include "dd.h"
#include <iostream.h>
class A {
private:
const int x;
enum { num =10};
static int y,z;
int arr[num];
public:
A (int val = 0):x(val)
{
for (int i=0;i<x;i++)
{
arr[i] = i;
}
cout<<"static value1 A::y = "<<y<<endl;
y = 0;
cout<<"static value2 A::y = "<<y<<endl;
}
~A(){cout<<"destructor..."<<endl;}
void printf();
};
void A::printf()
{
y = 121;
cout<<"const value A::x = "<<x<<endl;
cout<<"static value A::y = "<<y<<endl;
cout<<"static value A::z = "<<z<<endl;
for (int i=0;i<num;i++)
cout<<arr[i]<<"\t"<<endl;
}
int A::y =120;
int A::z =130;
int main()
{
A a(5) ;
a.printf();
A b(4) ;
b.printf();
i = 12;
return 0;
}
#include <iostream.h>
class A {
private:
const int x;
enum { num =10};
static int y,z;
int arr[num];
public:
A (int val = 0):x(val)
{
for (int i=0;i<x;i++)
{
arr[i] = i;
}
cout<<"static value1 A::y = "<<y<<endl;
y = 0;
cout<<"static value2 A::y = "<<y<<endl;
}
~A(){cout<<"destructor..."<<endl;}
void printf();
};
void A::printf()
{
y = 121;
cout<<"const value A::x = "<<x<<endl;
cout<<"static value A::y = "<<y<<endl;
cout<<"static value A::z = "<<z<<endl;
for (int i=0;i<num;i++)
cout<<arr[i]<<"\t"<<endl;
}
int A::y =120;
int A::z =130;
int main()
{
A a(5) ;
a.printf();
A b(4) ;
b.printf();
i = 12;
return 0;
}