c++ - 是否可以使用在另一个 C++ 库中声明的静态变量
问题描述
我打算在其函数之一中使用带有变量声明的库
/// in library A
function fun(){
static int iwanttouse = 1;
/// operation on iwanttouse
}
如何在应用程序 B 中使用它?我是否将其与外部连接
extern int iwanttouse;
// and then use it
if(iwanttouse == x)
.....
或者我可以在没有声明的情况下使用它们?
解决方案
不,静态变量具有内部链接,正是因为您不能这样做。
推荐阅读
- python - How to draw a square in an image from its center (x,y) in opencv Python?
- spring-boot - 在 Spring Boot+JMS+IBM MQ Durable Topic 监听器中设置 brokerDurSubQueue 属性
- r - R:在 R 中创建递归二叉树
- javascript - 我正在尝试使用一个按钮将背景颜色恢复为加载页面时的渐变色
- outlook - :iCal 事件未添加到组织者日历中
- mule - 在 Mule 中管理和操作大型 sql 查询的最佳方法
- javascript - 如何在 JavaScript onclick 上显示不同的图像并在第 3 次或第 4 次单击时显示相同的图像
- python - Python 3 int 和字符串转换
- mysql - Mysql:获取记录数
- mapbox - 通过使用 Mapbox 的过滤器进行高效加载