我正在尝试用C++创建一个禁止使用默认构造函数的类.
然而,我认为我失败了,或者我不理解幕后发生的事情.这是我到目前为止:
class Point {
public:
float x;
float y;
Point(float newX, float newY); //Definition is irrelevant
Point() = delete; //Default or "empty" constructor is forbidden, so deleted
}
/* ... */
int main(void)
{
Point a(1, 2); //Ok, should be available
Point b; //Ok, does not compile
Point c(); //Not ok, it does compile :(
}
Run Code Online (Sandbox Code Playgroud)
我的预期行为是c点不编译.我很感激帮助产生这样的行为,或者如果不可能的话,解释为什么这样的行为.
先感谢您