Volumes Of Fun http://www.volumesoffun.com/phpBB3/ |
|
Declaring LargeVolume<uint8_t> inside a struct http://www.volumesoffun.com/phpBB3/viewtopic.php?f=14&t=499 |
Page 1 of 1 |
Author: | Clonkex [ Tue Apr 16, 2013 3:33 am ] |
Post subject: | Declaring LargeVolume<uint8_t> inside a struct |
Hi, I want to be able to create a "vector" of volumes, in this case using LargeVolume<uint8_t>, but I see no way of doing this because you went and overloaded and protected the "=" operator. I first tried this: Code: struct volumeInfo { LargeVolume<uint8_t> volume; }; vector<volumeInfo> volume; But that can't compile because there's no default constructor for LargeVolume. Then I tried this: Code: vector<LargeVolume<uint8_t>> volume; That does compile but then I have no way using volume.push_back() because the vector code itself tries to use the "=" operator. How would you achieve this? Do you use the 'template' keyword in the declaration or something? EDIT: So then I thought, ah, stuff this, for the time being I'll just use a single terrain in a global variable. Well turns out that won't work either, because I can't just declare a global variable in my header because LargeVolume has no default constructor. Why'd you have to make this so difficult?? ![]() EDIT2: I wondered whether it might be possible achieve this via pointers, so I tried, but of course you can't assign just the memory address or the data will evaporate the moment you leave the function and you can't assign the data because it uses the "=" operator. Clonkex |
Author: | David Williams [ Tue Apr 16, 2013 9:07 am ] |
Post subject: | Re: Declaring LargeVolume<uint8_t> inside a struct |
Hi, it is possible to do what you want but I would be curious to know why you want to do this. In particular you should make sure you have read the first entry in the FAQ: http://www.volumesoffun.com/polyvox/doc ... aller-ones If you do want multiple volumes stored in a vector then your vector should actually just store pointers (as you suggest). The volumes should then be allocated on the heap (using 'new') in which case they won't disappear until you explicitly call 'delete'. operator=() is hidden basically for performance rasons - copying a volume is very expensive due to the large amount of data, and generally it's not an operation which you need to perform. |
Author: | Clonkex [ Tue Apr 16, 2013 9:49 am ] |
Post subject: | Re: Declaring LargeVolume<uint8_t> inside a struct |
Thank you so much for explaining that! ![]() I considered using 'new' and 'delete' but not at the same time as considering pointers so the two never clicked. Quote: Hi, it is possible to do what you want but I would be curious to know why you want to do this. In particular you should make sure you have read the first entry in the FAQ: http://www.volumesoffun.com/polyvox/doc ... aller-ones Lol, I actually found the FAQ and read the entire thing because I was trying to pass the time until you woke up and answered my post (I'd tried everything I could think of to make it work). I live in Australia so it's 7.45pm here at the moment ![]() ![]() The reason I want to be able to create lots of different volumes is not to create a single large terrain made of lots of volumes (I know you were thinking that ![]() I've been using DBPro since May 2010 (which is pretty much when I started learning to program) and I absolutely love it. There's only two drawbacks that I've come across so far: It's Windows-only and no one has yet created a plugin to allow batching ![]() Thanks a lot (that phrase always comes across as sarcastic) for your help ![]() ![]() Clonkex |
Page 1 of 1 | All times are UTC |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |