C++调用另一个静态函数的静态函数

3
在头文件中定义一个静态函数。
    class Diagnostics {
    public:


    static void functionA(){
    }

    static void functionB(){
    some code //works fine until enters the loop below
    variable_name // works fine here.
    if (condition){ // 
    variable_name; // after condition is met , i step in here, debugger cannot examine
                   // the vairable_name which was fine above. right after i try to step                      over , i get SIGSEV error
    some_code; // doesnt even come here. Process exited with SIGSEV
    function C(); // tried using classname::functionC , didnt work either

        }
    }

static void functionC(){
}

1
问题是什么?我不会期望在类定义或前面的代码中找到 variable_name - 它没有被提及。而且如果它没有被找到,这个过程怎么可能以 SIGSEGV 退出呢?如果没有找到 variable_name,它就不会编译通过。 - Steve Jessop
1
variable_name是什么?some_code是什么?它们在哪里定义?此外,您的函数缺少返回类型。 - casablanca
1
请展示给我们确切的代码。 - Prasoon Saurav
变量名是非静态类成员吗?如果是,那就是你的问题。 - GWW
5
嗯,我也找不到variable_name... - Mike DeSimone
显示剩余3条评论
2个回答

4

class中的static表示该成员或方法不作用于对象,即它不定义this,但仍然在类的命名空间中。

class外的static与C语言中的含义相同:变量或函数没有外部链接,即当前编译单元之外的东西不能链接到它。

两种完全不同的事情。


也许你感到困惑是因为原帖中的代码缩进不正确。我已经修复了它,现在你应该能看出为什么这个答案不起作用了。(即functionC是类的成员) - Billy ONeal

0

我不知道问题出在哪里。 现在运行正常。最初是在调试时发生的。 然后我只是执行而不是调试,结果很好。 然后我再次尝试调试,这次也正常了。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接