标签: static

我可以在静态类中拥有非静态数据成员吗?

我想知道在静态类中,所有方法和数据成员应该是静态的还是可以找到非静态成员?

c# static static-methods static-members

-5
推荐指数
1
解决办法
2375
查看次数

c ++为什么我不能使用static_cast将char*转换为int?

number = static_cast<int>(argv[1]);
Run Code Online (Sandbox Code Playgroud)

错误:使用static_cast从char*转换为int不允许.

我试过在谷歌上找出原因,我似乎无法找到它.另外,我不想得到ascii值,因为argv [1]是一个数字.

例如./prog 15

cout <<数字; //想要打印15

c++ int static casting

-5
推荐指数
1
解决办法
3703
查看次数

为什么此代码中的`bar`没有静态存储持续时间?

代码优先:

#include <stdio.h>

void foo()
{
        static int bar;
}

int main()
{
        bar++;
        return 0;
}
Run Code Online (Sandbox Code Playgroud)

编译器(Clang)抱怨:

static.c:10:2: error: use of undeclared identifier 'bar'
Run Code Online (Sandbox Code Playgroud)

该语句static int bar;中是否应该foo()给出bar静态存储持续时间,这使得它在main函数之前声明并初始化?

c static scope declaration

-7
推荐指数
1
解决办法
66
查看次数

为什么 C++ 中的 static 给出两个不同的值。调用函数后首先是 5,然后是 1?

下面的 static 关键字代码在调用函数之前和之后给出了两个不同的输出

#include<stdio.h>
static int count=5;
int fun()
{
    count = 0;
    count++;
    return count;
}
int main()
{
    printf("%d ", count);
    
    printf("%d ", fun());
    printf("%d ", fun());
    printf("%d ", count);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

输出:5 1 1 1

问)为什么 count 给出两个不同的值;一开始是5,调用函数后就变成1了?

c++ static static-methods

-7
推荐指数
1
解决办法
106
查看次数

我需要对静态意味着什么有一个非常基本的了解

我是一个java新手,尽管到处搜索,我找不到静态实际做什么的基本定义.有人可以告诉我这是什么意思吗?另外,请说出你的答案,好像我甚至不知道java是什么,没有编程语言的例子吗?非常感谢.编辑:所以我的理解是,当你在构造函数中有一个静态变量时,

i.e. you have 
class test{
   static int a = 5;
   public test(){
}

}
Run Code Online (Sandbox Code Playgroud)

然后

test test1 = new test();
test test2 = new test():
Run Code Online (Sandbox Code Playgroud)

,test1.a等于5,test2.a也等于5.如果你改变了test1.a = 6,test2.a也会等于6?

java static

-8
推荐指数
2
解决办法
1669
查看次数

标签 统计

static ×5

c++ ×2

static-methods ×2

c ×1

c# ×1

casting ×1

declaration ×1

int ×1

java ×1

scope ×1

static-members ×1