首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

變數問題!解决办法

2012-03-26 
變數問題!?請問變數該如何變全域變數?小弟在 main.h 內宣告C/C++ codeextern char* b在 main.cpp 內C/C++

變數問題!?
請問變數該如何變全域變數?

小弟在 main.h 內宣告

C/C++ code
extern char* b;



在 main.cpp 內


C/C++ code
Count=SizeY*WriteGoal*SizeX;char* b=new char[Count];memset(b,0,Count);


↑ 確實有開出記憶體空間

在 data.cpp 內宣告

C/C++ code
char* b;
(Global)



這樣為什麼還是不能使用呢?

詳細使用方法 http://topic.csdn.net/u/20120315/20/62d1fc2f-6fd9-4614-b044-bcef2dbda790.html

[解决办法]
test.h---------------
extern char *b;

void Tmalloc();


test.cpp---------------
#include "test.h"

char* b;
void Tmalloc()
{
b=new char[10];
memset(b,0,10);
memcpy_s(b, 10, "abc",4);
}

data.cpp----------------------------
extern char *b;

void main()
{
Tmalloc();
memset(b,0,10);
}

热点排行