声明全局变量的问题 [英] problem with declare global variable

查看:68
本文介绍了声明全局变量的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要定义一个很多文件都会看到它的全局变量,这个变量是一个指向class的指针。但是我做不到。

我有一组分别在分隔文件中的类

I need to define a global variable that many files will see it, this variable is a pointer to class. but i failed to do it.
I have a set of classes each in separated files

推荐答案

你有什么代码?声明一个类指针应该像ClassName * pMyClass;
What code do you have already? Declaring a class pointer should be as simple as ClassName *pMyClass;


yeap一样简单,但我需要所有其他文件看到它
yeap, but i need all other files see it



yeap,但我需要所有其他文件看到它
yeap, but i need all other files see it



如果你声明任何括号之外的东西它变成全局的。如果要在其他文件中使用它,则必须使用extern关键字。或者您也可以在标题中声明它并让两个cpp文件都包含该标题。

If you declare something outside of any brackets it becomes global. If you want to use it in another file you will have to use the extern keyword. Or you can also declare it in a header and have both cpp files include that header.


这篇关于声明全局变量的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆