从 int 到非标量类型“point”的 C++ 转换出现错误:

Aak*_*ari -1 c++ c++14

1.在这段代码中我想构造一个点类型的数组并将其每个索引的值初始化为1,2

我可以实现以下代码吗???

2.如果以下代码不起作用,正确的方法是什么???

#include<iostream>
using namespace std;
class point
{
 private:
   int x,y;
 public:
   point(int a,int b)
   {
       cout<<"constructor called here"<<endl;
       x=a;
       y=b;
   }
};

int main()
{
point p[2]{(1,2),(1,2)}; 
}
Run Code Online (Sandbox Code Playgroud)

Jar*_*d42 5

您应该使用{}而不是()

point p[2]{{1,2}, {1,2}}; 
Run Code Online (Sandbox Code Playgroud)

或使用类名:

point p[2]{point(1,2), point(1,2)}; 
Run Code Online (Sandbox Code Playgroud)