所以我在一个简单的坐标系统长时间休息之后今天写了一些C++,我想我想要一个构造函数来接受2个值,这样我就可以写出像"Coordinates c = new Coordinates(1,2);"这样的东西.
struct Coordinates {
int x;
int y;
Coordinates(int a, int b) {
x = a;
y = b;
}
};
Run Code Online (Sandbox Code Playgroud)
在Cygwin中编译时,我得到:
$ g ++ -o adventure adventure.cpp adventure.cpp:36:错误:没有匹配函数来调用`Coordinates :: Coordinates()'adventure.cpp:22:注意:候选者是:Coordinates :: Coordinates(const Coordinates&)冒险.cpp:26:注意:Coordinates :: Coordinates(int,int)
不知道这里出了什么问题,我在C++ struct构造函数上找不到太多信息.有任何想法吗?