小编Jig*_*asa的帖子

在不同范围内声明的静态变量之间的差异

在块内声明静态变量和在文件中的块外部之间有什么区别?例如,这里,静态变量a,b,c,d之间有什么区别?我们可以声明一个可以从程序的所有文件访问的静态变量吗?

    static int a;
    void getVol(..)
    { 
       static int b;
    }

    int main()
    {
       static int c;
       while(condition)
       {
           static int d;
            ....
       }
    some code here;
    return 0;
    }
Run Code Online (Sandbox Code Playgroud)

c++ static

4
推荐指数
1
解决办法
3144
查看次数

链接未在Makefile中完成

我尝试使用文件main.cpp,factorial.cpp,hello.cpp和function.h制作一个Makefile.在Linux命令窗口输入'make',它显示:

g++ -c -o hello main.o factorial.o hello.o
g++: main.o: linker input file unused because linking not done
g++: factorial.o: linker input file unused because linking not done
g++: hello.o: linker input file unused because linking not done
Run Code Online (Sandbox Code Playgroud)

我是第一次制作Makefile.请提出建议可能是什么问题?Makefile包含以下代码 - >

hello: main.o factorial.o hello.o
        g++ -c -o hello main.o factorial.o hello.o

main.o: main.cpp
        g++ -c -o main.o main.cpp

factorial.o: factorial.cpp
        g++ -c -o factorial.o factorial.cpp

hello.o: hello.cpp
        g++ -c -o hello.o hello.cpp
Run Code Online (Sandbox Code Playgroud)

如果你想看到的单个文件内容是:1)main.cpp

#include<iostream>
#include"functions.h"
using namespace std;
int …
Run Code Online (Sandbox Code Playgroud)

c++ makefile

4
推荐指数
2
解决办法
9203
查看次数

单击一个按钮以显示或隐藏表格

请参阅附带此问题的图片。我有四张桌子。当我单击某些表名称(例如表1)时,我希望该表显示在右侧。当我单击其他表名时,上一个应消失,而现在应显示一个。
我只知道html。因此,请告诉我是否可以单独使用html完成。如果没有,我只能使用CSS和JavaScript(这两种方法都是我的新手,将根据您的回答了解它们是否会有所帮助)。如果只能使用这三种语言(即HTML,CSS和JavaScript)实现此目标,请告诉。

html javascript css

3
推荐指数
1
解决办法
5万
查看次数

私有静态变量

为什么我们必须声明静态成员函数来访问私有静态变量?为什么不简单地使用公共函数来访问s_nValue?我的意思是为什么使用静态成员函数而不是非静态公共函数更好?

class Something
{
  private:
  static int s_nValue;

};

int Something::s_nValue = 1; // initializer


int main()
{

}
Run Code Online (Sandbox Code Playgroud)

c++ static class

0
推荐指数
1
解决办法
853
查看次数

带字符串和字符数组的不同输出

当我使用以下代码将字符串转换为浮点数时,它工作正常.但是下一个代码会给出错误.请告诉我为什么会这样?String是一个char数组,只是我读过的.

Code1(工作)

#include<iostream>
#include<stdlib.h>


using namespace std;

int main()
{
    char str[]="301.23";
    float f=atof(str);
    cout<<sizeof(str)<<" is size with contents "<<str<<endl;
    cout<<sizeof(f)<<" is size with contents "<<f<<endl;

return 0;
}
Run Code Online (Sandbox Code Playgroud)

代码2(不工作)

#include<stdlib.h>
#include<string>
#include<iostream>


using namespace std;

int main()
{
    string str="301.23";
    float f=atof(str);
    cout<<sizeof(str)<<" is size with contents "<<str<<endl;
    cout<<sizeof(f)<<" is size with contents "<<f<<endl;

return 0;
}
Run Code Online (Sandbox Code Playgroud)

错误:

 error: cannot convert std::string to const char* for argument 1 to double atof(const char*)
Run Code Online (Sandbox Code Playgroud)

请帮忙

c++

-4
推荐指数
1
解决办法
143
查看次数

标签 统计

c++ ×4

static ×2

class ×1

css ×1

html ×1

javascript ×1

makefile ×1