为什么不能将函数参数声明为静态? 我一直好奇为什么C++不允许声明静态函数参数,如下面所示: int test(static int a ) { return a; } int main() { test(5); return 0; }

为什么不能将函数参数声明为静态? 我一直好奇为什么C++不允许声明静态函数参数,如下面所示: int test(static int a ) { return a; } int main() { test(5); return 0; },c++,static,c++14,C++,Static,C++14,输出控制台显示: 更新#1: 我可以达到以下要求: int test(int a ) { static int count = 0;// <-- I want to eliminate this line due to some project constraints. count += a; return count; } int测试(int a) { static int count=0;//要声明一个静态函数,您可以这样做 static int te

输出控制台显示:

更新#1: 我可以达到以下要求:

int test(int a )
{
     static int count = 0;// <-- I want to eliminate this line due to some project constraints.
     count += a; 
     return count;
}
int测试(int a)
{

static int count=0;//要声明一个静态函数,您可以这样做

static int test(int a )
{
     return a;
}
您正试图将“static int a”传递到函数中,但没有理由这样做。您应该声明

static int a; 
然后简单地将

test(a);

你希望它有什么样的行为?这对我来说是不直观的,所以对期望的解释会很好。你可以自由地考虑它并讨论STD建议。C++有很多荒谬的东西,为什么要选择这个?请解释这与通常的传递变量有什么不同?@克里斯POst更新。它现在澄清了我的问题吗?@prahadpatil那么你想忽略
a
的所有新值,而不是第一次调用的值吗?这是一个非常不寻常的要求。你是对的,但我有一些限制。我不能简单地使用这个解决方案。我在我的帖子中添加了更多的细节。请检查。
test(a);