Skip to main content
gamedev.net
🔒 Locked

Nested Structures

Started by bower12345 May 14, 2003 at 12:13 AM 5 replies 450+ views
Original Post
bower12345
bower12345
Hey Folks, Quick Problem...I''m having a problem nesting structures within other structures. Is this allowed? And if so, is there a certain way to access the data inside of the structures. I am doing something like this.
  
struct Square_Wave_One
{
   struct Sound_Reg_4000
   {
      BYTE Yadda1,
           Yadda2,
           Yadda3;
   };
};
  
Then to access the elements within those structures I am trying something like this:
  
Square_Wave_One.Sound_Reg_4000.Yadda1 = (Value & 0x0F);
  
I just can''t seem to figure out if I''m doing something wrong. If you folks need me to post full source, please let me know. Regards, Mike
Mikehttp://cs.wpunj.edu/~bowersom
digitec devil
digitec devil

  
struct Sound_Reg_4000 { BYTE Yadda1, Yadda2, Yadda3; };

struct Square_Wave_One{ struct Sound_Reg_4000 sr4; };

bower12345
bower12345
Sorry,

That solution didn''t work for the code. Any other ideas?

Regards,
Mike
Mikehttp://cs.wpunj.edu/~bowersom
digitec devil
digitec devil

    
//given these definitions

struct Sound_Reg_4000 {
BYTE Yadda1,
Yadda2,
Yadda3; };
struct Square_Wave_One{ struct Sound_Reg_4000 sr4; };

//declare a struct Square_Wave_One like this

struct Square_Wave_One sw1;

sw1.sr4.Yadda1 = whatever;
sw1.sr4.Yadda2 = whatever;
sw1.sr4.Yadda3 = whatever;


failing that, yes you'll need to post more code.

EDIT: typos

[edited by - digitec devil on May 14, 2003 1:48:00 AM]
Qw3r7yU10p!
Qw3r7yU10p!
Nesting a class inside another doesnt make an instance of that class. It just puts it in the scope. You need to add a member which is an instance of the class if you want to store actual data.


  
#include <iostream>

class empty{
public:
class full {
int bigThing[1000];
};
};

int main() {
using std:: cout;
using std::endl;

cout << "sizeof(full) " << sizeof(empty::full) << endl;
cout << "sizeof(empty) " << sizeof(empty) << endl;
return 0;
}


On my machine this prints:
sizeof(full) 4000
sizeof(empty) 1


An object has to have size at least 1 to be able to exist at a memory location. But aside from that empty contains no data.

If you were to make empty have a member you''d get very different results:

  
class empty{
public:
class full {
int bigThing[1000];
};
full noLongerEmpty;
};


sizeof(full) 4000
sizeof(empty) 4000


Hope this helps
rotos
rotos

    
struct Square_Wave_One
{
struct
{
BYTE Yadda1,
Yadda2,
Yadda3;
} Sound_Reg_4000;
};


Put the name at the end like above, and you can access it just like you wanted to in the first place.

Good luck with your NES APU emulator .
bower12345
bower12345
Thanks much Rotos, it worked perfectly...do you any good references on DirectSound where I can learn how to play different tones and whatnot I receve from the channels? Thanks in Advance.

Regards,
Mike
Mikehttp://cs.wpunj.edu/~bowersom

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.