   Pointers to class objects
  I was compiling some code, and the compiler told me that the following code was invalid:Foo *pFoo_1 = Foo Foo_1;I was, however, allowed to declare my object on the heap:Foo *pFoo_1 = new Foo;Why would I be able to place a pointer to a class object on the heap but not the stack as well?ooo.  Is it because I wasn't assigning pFoo_1 to an address...  I suppose    Foo *pFoo_1 = Foo &Foo_1;would have workedSo what's your take on my conundrum here?   
  This line isn;t really valid:Foo *pFoo_1 = Foo Foo_1;What you want is probably:Foo Foo_1;//put an object on the stackFoo *pFoo_1 = &Foo_1;//get the address   ;Quote:Original post by zoner7I suppose    Foo *pFoo_1 = Foo &Foo_1;would have workedNo this is invalid syntax and should yield a compiler error as well. Hodgman has already posted how to get the adress of a variable on the stack. But just keep in mind that you are not allowed to delete this pointer and its associated memory. So it is rather dangerous and error prone to store pointes on stack variables.;  What you can have is a reference to a constant Foo.Foo const& ref = Foo();Although this is completely pointless.   