vendredi 1 décembre 2017

Dont allow use of default constructor in C++ [duplicate]

This question already has an answer here:

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