# include "test.h"
int i = 0;
test :: test(){
}
test :: ~test(){
}
int test::getNumber(){
return i;
}
class test{
public:
int i ;
test();
~test();
int getNumber();
};
// test_2.cpp : Defines the entry point for the console application.
#include
#include
#include "test.h"
using namespace std;
int main(int argc, char* argv[])
{
test t;
int s =t.getNumber();
cout << "number is :"<< s << endl;
return 0;
}
各位大侠 这端程序运行完后输出地应该是 0 吧可是为什么输出地是-90922334这样的数字呢我很费解 刚开始研究c++ 问题有些菜哈 大家请赐教~~~
# include "test.h"int i = 0;//此处的i作用域是全局的class test{ public:int i ;//这里重新声明了i,作用域在类test内,getNumber返回的就是此没有赋值的i,去掉此行就返回全局i的值0test();~test();int getNumber();};