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 predefinedCaptu reSetting
{
int buffer_signal;
int transform_signa l;
bool only_solid;
bool line_as_solid;
bool no_texture;
bool optimize_geomet ry;
bool recompute_norma ls;
bool last_frame;
};
predefinedCaptu reSetting PredefinedSetti ng[25];
PredefinedSetti ng[0] = {1,0,false,fals e,false,true,tr ue,false};
PredefinedSetti ng[1] = {1,1,false,fals e,false,true,tr ue,false};
PredefinedSetti ng[2] = {0,1,false,fals e,false,true,tr ue,false};
....
....
PredefinedSetti ng[22] = {1,1,false,fals e,false,true,tr ue,false};
PredefinedSetti ng[23] = {1,0,false,fals e,false,true,tr ue,false};
PredefinedSetti ng[24] = {1,1,false,fals e,false,true,tr ue,false};
Is there any reason why the above code wouldn't work? Thanks for any
help 5 2821
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 predefinedCaptu reSetting { int buffer_signal; int transform_signa l; bool only_solid; bool line_as_solid; bool no_texture; bool optimize_geomet ry; bool recompute_norma ls; bool last_frame; };
predefinedCaptu reSetting PredefinedSetti ng[25]; PredefinedSetti ng[0] = {1,0,false,fals e,false,true,tr ue,false}; PredefinedSetti ng[1] = {1,1,false,fals e,false,true,tr ue,false}; PredefinedSetti ng[2] = {0,1,false,fals e,false,true,tr ue,false}; ... ... PredefinedSetti ng[22] = {1,1,false,fals e,false,true,tr ue,false}; PredefinedSetti ng[23] = {1,0,false,fals e,false,true,tr ue,false}; PredefinedSetti ng[24] = {1,1,false,fals e,false,true,tr ue,false};
Is there any reason why the above code wouldn't work? Thanks for any help
Try the following:
predefinedCaptu reSetting PredefinedSetti ng[25] =
{
{1,0,false,fals e,false,true,tr ue,false},
{1,1,false,fals e,false,true,tr ue,false},
{0,1,false,fals e,false,true,tr ue,false},
....
{1,1,false,fals e,false,true,tr ue,false},
{1,0,false,fals e,false,true,tr ue,false},
{1,1,false,fals e,false,true,tr ue,false}
};
Michael Mellor
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 predefinedCaptu reSetting { int buffer_signal; int transform_signa l; bool only_solid; bool line_as_solid; bool no_texture; bool optimize_geomet ry; bool recompute_norma ls; bool last_frame; };
predefinedCaptu reSetting PredefinedSetti ng[25]; PredefinedSetti ng[0] = {1,0,false,fals e,false,true,tr ue,false}; PredefinedSetti ng[1] = {1,1,false,fals e,false,true,tr ue,false}; PredefinedSetti ng[2] = {0,1,false,fals e,false,true,tr ue,false}; ... ... PredefinedSetti ng[22] = {1,1,false,fals e,false,true,tr ue,false}; PredefinedSetti ng[23] = {1,0,false,fals e,false,true,tr ue,false}; PredefinedSetti ng[24] = {1,1,false,fals e,false,true,tr ue,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 predefinedCaptu reSetting
{
predefinedCaptu reSetting( int buffer, int transform, bool only, bool line, bool no_text,
bool opt, bool recompute, bool last )
: buffer_signal( buffer ),
transform_signa l( transform ),
only_solid( only ),
line_as_solid( line ),
no_texture( no_text ),
optimize_geomet ry( opt ),
recompute_norma ls( recompute ),
last_frame( last )
{}
int buffer_signal;
int transform_signa l;
bool only_solid;
bool line_as_solid;
bool no_texture;
bool optimize_geomet ry;
bool recompute_norma ls;
bool last_frame;
};
Then you can write:
PredefinedSetti ng[0] = predefinedCaptu reSetting( 1,0,false,false ,false,true,tru e,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
Kenny McCarty <ke***@barmeist er.com> wrote in message
news:58******** *************** ***@posting.goo gle.com... 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 predefinedCaptu reSetting { int buffer_signal; int transform_signa l; bool only_solid; bool line_as_solid; bool no_texture; bool optimize_geomet ry; bool recompute_norma ls; bool last_frame; };
predefinedCaptu reSetting PredefinedSetti ng[25]; PredefinedSetti ng[0] = {1,0,false,fals e,false,true,tr ue,false}; PredefinedSetti ng[1] = {1,1,false,fals e,false,true,tr ue,false}; PredefinedSetti ng[2] = {0,1,false,fals e,false,true,tr ue,false}; ... ... PredefinedSetti ng[22] = {1,1,false,fals e,false,true,tr ue,false}; PredefinedSetti ng[23] = {1,0,false,fals e,false,true,tr ue,false}; PredefinedSetti ng[24] = {1,1,false,fals e,false,true,tr ue,false};
Is there any reason why the above code wouldn't work? Thanks for any help
Note that predefinedCaptu reSetting's fields are shrinked and the array,
PredefinedSetti ng's size reduced just to show an example.
struct predefinedCaptu reSetting
{
int buffer_signal;
int transform_signa l;
bool only_solid;
predefinedCaptu reSetting(int buf = 1, int tra = 1, bool onl = false) :
buffer_signal(b uf), transform_signa l(tra), only_solid(onl) {}
};
predefinedCaptu reSetting PredefinedSetti ng[3] =
predefinedCaptu reSetting(1,0,f alse),
predefinedCaptu reSetting(0,0,f alse),
predefinedCaptu reSetting(0,1,f alse) };
In article <58************ **************@ posting.google. com>, ke***@barmeiste r.com says...
[ ... ] predefinedCaptu reSetting PredefinedSetti ng[25]; PredefinedSetti ng[0] = {1,0,false,fals e,false,true,tr ue,false}; PredefinedSetti ng[1] = {1,1,false,fals e,false,true,tr ue,false}; PredefinedSetti ng[2] = {0,1,false,fals e,false,true,tr ue,false};
This syntax only works for initialization, not assignment, so you can do
this:
predefinedCaptu reSetting PredefinedSetti ng[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:
PredefinedSetti ng[0] =
PredefinedCaptu reSetting(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_GEOMET RY | RECOMPUTE_NORMA LS);
At least to me, "OPTIMIZE_GEOME TRY | RECOMPUTE_NORMA LS" 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.
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 :-) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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;
};
|
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 call INDV. The struct
looks like
// Some info used for the struct
typedef unsigned char uint8; /* 8 bits */
|
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;
|
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 the structure inside the array.
When I try this, an error about late assignment appears. Is it possible to
assign a value to a structure field that is in an array?
I'm currently getting around the problem by creating a new structure, assign...
|
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 now
thown out of the array released properly by the CLI?
| |
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. This
works without any problems. I now would like to filter "duplicate"
records. They aren't really duplicate, I can't just qsort as is and
eliminate the matching rows. I have number of fields that will be the
same, but some of the fields will...
|
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 must be allocated (with known max length = 10) before the call to
the dll function (the dll just fills it ,with no allocations).
The definitions of Mystruct and :
|
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
ptrLogArray = new structDisplayLogData *;
// iCount = 50 structDisplayLogData is a strcuture of data
Thanks
|
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 structs. The array of structs are allocated
by C#.
If I pass the array without 'ref' it works fine on the C++ side, but
after returning to C# the array struct values are all zero. If I pass
with 'ref' the application crashes. If I use a class...
|
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 mallocing space
for the pointer 'countPtr' in each struct, but do I need to do
anything else? Thanks.
typedef struct TwoCounts {
int *countPtr;
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |