I'm wondering why this code compiles correctly. Since the copy-constructor and assignement-operator are deleted, I thought these mechanics would not be available.
I'm thinking that the constructions in main() are substituted by the compiler with some kind of emplace construction effectively made by Object itself... but I couldn't figure why or how that would happen.
struct Object
{
private:
friend struct ObjectFactory;
Object() {}
Object(const Object& other) = delete;
Object& operator=(const Object&) const = delete;
};
struct ObjectFactory
{
static Object CreateObject() { return Object(); }
};
int main()
{
Object object1 = ObjectFactory::CreateObject();
Object object2 ( ObjectFactory::CreateObject() );
Object object3 { ObjectFactory::CreateObject() };
}