Kavya:
That createless a nameless object which exists until the end of the
statement. The following two snippets are equivalent:
int main()
{
int i = MyClass().GetVal();
}
int main()
{
int i;
{
MyClass nameless_object;
i = nameless_object.GetVal();
}
}
If you would like to invoke a class's constructor, you need to supply it
with a memory address at which to construct an object of the class in
question. "Placement new" is used for this:
void *const pmem = malloc(512);
MyClass *const p = ::new((void*)pmem) MyClass();
p->~MyClass();
free(pmem);