在下面的代码中,我似乎不理解花括号初始化的限制。它们实际上是做什么的?在A的情况下,它只是直接将a [0]设置为相应的值。在b的情况下,它使用隐式转换。它是根据可用的内容来决定要做什么,还是有其他方法来使用它?
这种花括号的初始化方式在Java中是否也可以使用类似的方法呢?
#include <iostream>
using namespace std;
struct A
{
};
struct B
{
B(int a) { cout << a; }
};
int main()
{
A* a[] = {new A()};
B b[] = {1};
}
这种花括号的初始化方式在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 */ }.
}
}
如果我的问题看起来很傻,请不要介意,我只是想更多地了解c++和Java中的花括号。谢谢!:-)