This question already has an answer here:
- Most vexing parse: why doesn't A a(()); work? 5 answers
- Default constructor with empty brackets 9 answers
I'm trying to create a class in C++ which forbids the use of the default constructor.
Nevertheless, I think I'm failing, or I'm not understanding what is happening behind the scenes. Here is what I have so far:
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 :(
}
My intended behavior is for point c not to compile. I'd appreciate help in generating such a behavior, or if not possible, an explanation of why this works like that.
Thank you in advance
Aucun commentaire:
Enregistrer un commentaire