D - Allocate a struct on the heap?
- Russ Lewis (12/12) Sep 20 2002 I feel kind of stupid to ask, since (I guess) this should be simple, but
- Russell Lewis (2/17) Sep 23 2002 Any thoughts on this, anybody?
- Patrick Down (16/27) Sep 23 2002 but
- Russell Lewis (2/40) Sep 23 2002 But why???
- Patrick Down (8/10) Sep 23 2002 You mean why can't you just do
- Walter (3/13) Sep 24 2002 Looks like a compiler bug to me. -Walter
I feel kind of stupid to ask, since (I guess) this should be simple, but how do you allocate a single instance of a struct on the heap? new doesn't work, giving the error "Error: new can only create arrays or class objects, not <structName>'s". I know, I could allocate an array of length 1, but what I really want is a pointer, not an array (I'm going to cast it to a void pointer soon, and send it flying through C-space...) -- The Villagers are Online! villagersonline.com .[ (the fox.(quick,brown)) jumped.over(the dog.lazy) ] .[ (a version.of(English).(precise.more)) is(possible) ] ?[ you want.to(help(develop(it))) ]
Sep 20 2002
Russ Lewis wrote:I feel kind of stupid to ask, since (I guess) this should be simple, but how do you allocate a single instance of a struct on the heap? new doesn't work, giving the error "Error: new can only create arrays or class objects, not <structName>'s". I know, I could allocate an array of length 1, but what I really want is a pointer, not an array (I'm going to cast it to a void pointer soon, and send it flying through C-space...) -- The Villagers are Online! villagersonline.com .[ (the fox.(quick,brown)) jumped.over(the dog.lazy) ] .[ (a version.of(English).(precise.more)) is(possible) ] ?[ you want.to(help(develop(it))) ]Any thoughts on this, anybody?
Sep 23 2002
Russell Lewis <spamhole-2001-07-16 deming-os.org> wrote in news:3D8F7EB9.8050305 deming-os.org:Russ Lewis wrote:butI feel kind of stupid to ask, since (I guess) this should be simple,ishow do you allocate a single instance of a struct on the heap? new doesn't work, giving the error "Error: new can only create arrays or class objects, not <structName>'s". I know, I could allocate an array of length 1, but what I really wantstruct Foo { int a; int b; } int main(char[][] argv) { Foo* pFoo = new Foo[1]; return 0; }a pointer, not an array (I'm going to cast it to a void pointer soon, and send it flying through C-space...)Any thoughts on this, anybody?
Sep 23 2002
Patrick Down wrote:Russell Lewis <spamhole-2001-07-16 deming-os.org> wrote in news:3D8F7EB9.8050305 deming-os.org:But why???Russ Lewis wrote:butI feel kind of stupid to ask, since (I guess) this should be simple,ishow do you allocate a single instance of a struct on the heap? new doesn't work, giving the error "Error: new can only create arrays or class objects, not <structName>'s". I know, I could allocate an array of length 1, but what I really wantstruct Foo { int a; int b; } int main(char[][] argv) { Foo* pFoo = new Foo[1]; return 0; }a pointer, not an array (I'm going to cast it to a void pointer soon, and send it flying through C-space...)Any thoughts on this, anybody?
Sep 23 2002
Russell Lewis <spamhole-2001-07-16 deming-os.org> wrote in news:3D8FAF8B.2050907 deming-os.org:But why???You mean why can't you just do Foo* p = new Foo; //?? I don't know. <g> new Foo[1] seems pretty much the same to me. It creates a block of heap memory large enough to hold one Foo.
Sep 23 2002
Looks like a compiler bug to me. -Walter "Patrick Down" <pat codemoon.com> wrote in message news:Xns9292CBA453F87patcodemooncom 63.105.9.61...Russell Lewis <spamhole-2001-07-16 deming-os.org> wrote in news:3D8FAF8B.2050907 deming-os.org:But why???You mean why can't you just do Foo* p = new Foo; //?? I don't know. <g> new Foo[1] seems pretty much the same to me. It creates a block of heap memory large enough to hold one Foo.
Sep 24 2002