473,396 Members | 1,938 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

array of structs

I am trying to create an array of structs and I am having problems
adding the values into the structure itself. Here is the code:

struct predefinedCaptureSetting
{
int buffer_signal;
int transform_signal;
bool only_solid;
bool line_as_solid;
bool no_texture;
bool optimize_geometry;
bool recompute_normals;
bool last_frame;
};

predefinedCaptureSetting PredefinedSetting[25];
PredefinedSetting[0] = {1,0,false,false,false,true,true,false};
PredefinedSetting[1] = {1,1,false,false,false,true,true,false};
PredefinedSetting[2] = {0,1,false,false,false,true,true,false};
....
....
PredefinedSetting[22] = {1,1,false,false,false,true,true,false};
PredefinedSetting[23] = {1,0,false,false,false,true,true,false};
PredefinedSetting[24] = {1,1,false,false,false,true,true,false};
Is there any reason why the above code wouldn't work? Thanks for any
help
Jul 22 '05 #1
5 2806
Kenny McCarty wrote:
I am trying to create an array of structs and I am having problems
adding the values into the structure itself. Here is the code:

struct predefinedCaptureSetting
{
int buffer_signal;
int transform_signal;
bool only_solid;
bool line_as_solid;
bool no_texture;
bool optimize_geometry;
bool recompute_normals;
bool last_frame;
};

predefinedCaptureSetting PredefinedSetting[25];
PredefinedSetting[0] = {1,0,false,false,false,true,true,false};
PredefinedSetting[1] = {1,1,false,false,false,true,true,false};
PredefinedSetting[2] = {0,1,false,false,false,true,true,false};
...
...
PredefinedSetting[22] = {1,1,false,false,false,true,true,false};
PredefinedSetting[23] = {1,0,false,false,false,true,true,false};
PredefinedSetting[24] = {1,1,false,false,false,true,true,false};
Is there any reason why the above code wouldn't work? Thanks for any
help


Try the following:

predefinedCaptureSetting PredefinedSetting[25] =
{
{1,0,false,false,false,true,true,false},
{1,1,false,false,false,true,true,false},
{0,1,false,false,false,true,true,false},
....
{1,1,false,false,false,true,true,false},
{1,0,false,false,false,true,true,false},
{1,1,false,false,false,true,true,false}
};

Michael Mellor
Jul 22 '05 #2
Kenny McCarty wrote:

I am trying to create an array of structs and I am having problems
adding the values into the structure itself. Here is the code:

struct predefinedCaptureSetting
{
int buffer_signal;
int transform_signal;
bool only_solid;
bool line_as_solid;
bool no_texture;
bool optimize_geometry;
bool recompute_normals;
bool last_frame;
};

predefinedCaptureSetting PredefinedSetting[25];
PredefinedSetting[0] = {1,0,false,false,false,true,true,false};
PredefinedSetting[1] = {1,1,false,false,false,true,true,false};
PredefinedSetting[2] = {0,1,false,false,false,true,true,false};
...
...
PredefinedSetting[22] = {1,1,false,false,false,true,true,false};
PredefinedSetting[23] = {1,0,false,false,false,true,true,false};
PredefinedSetting[24] = {1,1,false,false,false,true,true,false};

Is there any reason why the above code wouldn't work?


Sure.
The thing on the right side of the assignment isn't a struct
it is just a list of numbers and boolean values seperated
by comma and enclosed in { }.

But you can change that.
Give that structure a constructor (Surprise: yes you can do that.
In C++ there is no difference of a class and a struct except that
in a struct everything is public while in a class it is private and
inheritance is again public for structs by default while it is
private for a class).

struct predefinedCaptureSetting
{
predefinedCaptureSetting( int buffer, int transform, bool only, bool line, bool no_text,
bool opt, bool recompute, bool last )
: buffer_signal( buffer ),
transform_signal( transform ),
only_solid( only ),
line_as_solid( line ),
no_texture( no_text ),
optimize_geometry( opt ),
recompute_normals( recompute ),
last_frame( last )
{}

int buffer_signal;
int transform_signal;
bool only_solid;
bool line_as_solid;
bool no_texture;
bool optimize_geometry;
bool recompute_normals;
bool last_frame;
};

Then you can write:

PredefinedSetting[0] = predefinedCaptureSetting( 1,0,false,false,false,true,true,false );
May I ask which text book you are using?
Just that we start warning others about a C++ textbook which
hasn't a chapter on constructors.

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 22 '05 #3
Kenny McCarty <ke***@barmeister.com> wrote in message
news:58**************************@posting.google.c om...
I am trying to create an array of structs and I am having problems
adding the values into the structure itself. Here is the code:

struct predefinedCaptureSetting
{
int buffer_signal;
int transform_signal;
bool only_solid;
bool line_as_solid;
bool no_texture;
bool optimize_geometry;
bool recompute_normals;
bool last_frame;
};

predefinedCaptureSetting PredefinedSetting[25];
PredefinedSetting[0] = {1,0,false,false,false,true,true,false};
PredefinedSetting[1] = {1,1,false,false,false,true,true,false};
PredefinedSetting[2] = {0,1,false,false,false,true,true,false};
...
...
PredefinedSetting[22] = {1,1,false,false,false,true,true,false};
PredefinedSetting[23] = {1,0,false,false,false,true,true,false};
PredefinedSetting[24] = {1,1,false,false,false,true,true,false};
Is there any reason why the above code wouldn't work? Thanks for any
help


Note that predefinedCaptureSetting's fields are shrinked and the array,
PredefinedSetting's size reduced just to show an example.

struct predefinedCaptureSetting
{
int buffer_signal;
int transform_signal;
bool only_solid;

predefinedCaptureSetting(int buf = 1, int tra = 1, bool onl = false) :
buffer_signal(buf), transform_signal(tra), only_solid(onl){}
};

predefinedCaptureSetting PredefinedSetting[3] =
predefinedCaptureSetting(1,0,false),
predefinedCaptureSetting(0,0,false),
predefinedCaptureSetting(0,1,false) };
Jul 22 '05 #4
In article <58**************************@posting.google.com >,
ke***@barmeister.com says...

[ ... ]
predefinedCaptureSetting PredefinedSetting[25];
PredefinedSetting[0] = {1,0,false,false,false,true,true,false};
PredefinedSetting[1] = {1,1,false,false,false,true,true,false};
PredefinedSetting[2] = {0,1,false,false,false,true,true,false};


This syntax only works for initialization, not assignment, so you can do
this:

predefinedCaptureSetting PredefinedSetting[25] = {
{1, 0, false, false, false, true, true, false},
{1, 1, false, false, false, true, true, false},

and so on for all 25 items, or you can do something like:

PredefinedSetting[0] =
PredefinedCaptureSetting(1, 0, false, false, false, true, true, false);

and so on for 25 values.

On a different note, I think I'd define things a bit differently. I'd
probably define the bools as an int (or short, or whatever) and define
some names for bit positions, so your first item would be something
along this line:

Predef[0] = Setting(1, 0, OPTIMIZE_GEOMETRY | RECOMPUTE_NORMALS);

At least to me, "OPTIMIZE_GEOMETRY | RECOMPUTE_NORMALS" seems quite a
bit more meaningful than "false, false, false, true, true, false". The
latter is meaningful ONLY if somebody has memorized the order in which
you've arranged the fields -- and even then, you just about have to
count over to be sure whether a particular "true" is in the third or
fourth position (and adding even a couple more possibilities renders it
much more difficult still).

--
Later,
Jerry.

The universe is a figment of its own imagination.
Jul 22 '05 #5
Thank you everyone for your help. It has been a long time since I
last did any C++ coding so I was a little but rusty :-)
Jul 22 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Kieran Simkin | last post by:
Hi, I wonder if anyone can help me, I've been headscratching for a few hours over this. Basically, I've defined a struct called cache_object: struct cache_object { char hostname; char ipaddr;...
1
by: mrhicks | last post by:
Hello all, I need some advice/help on a particular problem I am having. I have a basic struct called "indv_rpt_rply" that holds information for a particular device in our system which I will...
5
by: Paminu | last post by:
Why make an array of pointers to structs, when it is possible to just make an array of structs? I have this struct: struct test { int a; int b;
26
by: Brett | last post by:
I have created a structure with five fields. I then create an array of this type of structure and place the structure into an array element. Say index one. I want to assign a value to field3 of...
7
by: heddy | last post by:
I have an array of objects. When I use Array.Resize<T>(ref Object,int Newsize); and the newsize is smaller then what the array was previously, are the resources allocated to the objects that are...
11
by: Cliff Martin | last post by:
Hi, I am reading a fairly large file a line at a time, doing some processing, and filtering out bits of the line. I am storing the interesting information in a struct and then printing it out....
6
by: =?Utf-8?B?QWxleGFuZGVyZmU=?= | last post by:
Hi, I have a C# program that uses an unmanaged dll that has a function similar to the signature below : void f(out MyStruct arr, out int num); // num = actual array length returned The array...
5
by: dev_15 | last post by:
Hi, I'm going through some code and thought that this allocates an array of structs but its supposed according to comments to allocate an array of pointer to structs. What does it actually do ...
2
by: jonpb | last post by:
Using .NET 3.5, I need to pass an array of structs as parameter to a C++ unmanaged function. The C++ dll stores some data in an unmanaged cache, the function writes the values into the array of...
2
by: hal | last post by:
Hi, I'm trying to make an array of pointers to 'TwoCounts' structs, where the size of the array is arraySize. Right now I'm just mallocing enough space for all the pointers to the structs, and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.