c++静态成员问题

来源:百度知道 编辑:UC知道 时间:2024/06/27 06:13:39
#include <iostream.h>
int i=1;
void main ()
{
static int a;
int b=-10;
int c=0;
void other ();
cout <<"--main--\n";
cout <<"i:"<<i<<"a:"<<a<<"b:"<<b<<"c:"<<c<<endl;
c=c+8; other ();
cout<<"---main--\n";
cout<<"i:"<<i<<"a:"<<a<<"b:"<<b<<"c:"<<c<<endl;
i+=10; other ();
}
void othrer ()
{
static int a=2;
static int b;
int c=10;
a+=2; i+=32;c+=5;
cout<<"--other--\n";
cout<<"i:"<<i<<"a:"<<a<<"b:"<<b<<"c:"<<c<<endl;
b=a;
}
运行后总是显示--------------------Configuration: static - Win32 Debug--------------------
Compiling...

下面是我给你修改后的程序,这次我是真的调试过的,绝对没有问题,骗你是小狗
#include <iostream.h>
int i=1;
void other(void);
void main()
{
static int a;
int b=-10;
int c=0;
other();
cout <<"--main--\n";
cout <<"i:"<<i<<"a:"<<a<<"b:"<<b<<"c:"<<c<<endl;
c=c+8; other();
cout<<"---main--\n";
cout<<"i:"<<i<<"a:"<<a<<"b:"<<b<<"c:"<<c<<endl;
i+=10; other();
}
void other(void)
{
static int a=2;
static int b;
int c=10;
a+=2; i+=32;c+=5;
cout<<"--other--\n";
cout<<"i:"<<i<<"a:"<<a<<"b:"<<b<<"c:"<<c<<endl;
b=a;
}

写在后面的函数在前面用要声明