As what's been said on the comments, you are lacking the parentheses needed to call the method.
Access()
// ^^ These
However, a more important issue to be solved here is your use of new
. Don't use it like you're using it now. By using it that way, you are creating a memory leak which you can never ever hope to reclaim because you would never have the chance to use delete
on it[1] (unless you close your program...).
To use temporaries in C++, just use a stack-based, automatic storage object (in other words, normal objects):
Sam().Access();
//^^^^^ This creates the temporary object
However, you must still be careful not to use that temporary in subsequent statements, a problem which is commonly encountered when mixing them with references.
Sam& bad_sam = Sam().I_Return_A_Reference_To_This_Object();
bad_sam.Access(); // Oh no!
In the above example, the temporary object created by Sam()
will be destroyed at the end of the statement (hence being temporary). bad_sam.Access();
would be illegal and would result in undefined behavior.
[1] Ahem says the language lawyers. Of course you can use delete this;
... To OP: don't!