相关疑难解决方法(0)

C++和Java中的Curly Bracket初始化

在下面的代码中,我似乎不理解大括号初始化的局限性.他们到底做了什么?在A的情况下,它只是将[0]设置为直接等于该值.在b的情况下,它使用隐式转换.它是根据可用的内容决定做哪一个,还是使用其他方法?

#include <iostream>

using namespace std;

struct A
{

};

struct B
{
    B(int a) { cout << a; }
};

int main()
{
    A* a[] = {new A()};
    B b[] = {1};    
}
Run Code Online (Sandbox Code Playgroud)

这种类型的花括号初始化在Java中的工作方式也类似吗?

public class A
{
     public static void main(String[] args)
     {
          someClass[] sC = { /* what can go here? an argument to the constructor,
                               or just a value to set the variable equal to */ }.
     }
}
Run Code Online (Sandbox Code Playgroud)

很抱歉,如果我的问题看起来很愚蠢,那么我真的想了解更多有关c ++和Java中的花括号的信息.提前致谢 :-)

c++ java arrays

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

标签 统计

arrays ×1

c++ ×1

java ×1