|
From: Pat on 19 Apr 2008 11:06 I'm in the process of teaching myself C++ (with the help of several good books) so I can develop some DLL's for another application. Looking through an example of one of these, there's a line that defines a structure as follows: struct ParameterDefinition primaryParams[]= { {"x position =", kXpos, 1.0} {"y position =", kYpos, 2.0} {"z position =", kZpos, 0.0} }; None of the books I've been reviewing define a structure in this way (at least so far). So what is "ParameterDefinition"? A pointer? I assume it actually contains the code that defines this structure type. Is there a name for this way defining a structure? I'd like to read more about that. Thanks.
From: Francis Glassborow on 19 Apr 2008 11:20 Pat wrote: > I'm in the process of teaching myself C++ (with the help of several good > books) so I can develop some DLL's for another application. > > Looking through an example of one of these, there's a line that defines > a structure as follows: > > struct ParameterDefinition primaryParams[]= > { > {"x position =", kXpos, 1.0} > {"y position =", kYpos, 2.0} > {"z position =", kZpos, 0.0} > }; > > > None of the books I've been reviewing define a structure in this way (at > least so far). So what is "ParameterDefinition"? A pointer? I assume > it actually contains the code that defines this structure type. Is > there a name for this way defining a structure? I'd like to read more > about that. No, you have misunderstood. The above is NOT a definition of a struct. struct ParameterDefinition is a type written in C form, C++ would just use ParameterDefinition (it does not need the prefix 'struct' to tell the compiler that the following is the name of a struct type. Now given that 'struct ParameterDefinition' is just a long winded name for a type we can read the whole declaration/definition as: primaryParams is an array (size to be deduced from the provided initialisers) of type ParameterDefinition which is to be initialised with three sets of values. Compare this with the simpler but similar int array[] = {1, 2, 3};
From: Barry Schwarz on 19 Apr 2008 13:55 On Sat, 19 Apr 2008 11:06:19 -0400, Pat <pkelecy@_REMOVETHIS_gmail.com> wrote: >I'm in the process of teaching myself C++ (with the help of several good >books) so I can develop some DLL's for another application. > >Looking through an example of one of these, there's a line that defines >a structure as follows: > >struct ParameterDefinition primaryParams[]= >{ > {"x position =", kXpos, 1.0} > {"y position =", kYpos, 2.0} > {"z position =", kZpos, 0.0} >}; > > >None of the books I've been reviewing define a structure in this way (at >least so far). So what is "ParameterDefinition"? A pointer? I assume >it actually contains the code that defines this structure type. Is >there a name for this way defining a structure? I'd like to read more >about that. This is an definition of an array of struct. The structure type (struct ParameterDefinition) has been declared elsewhere, possibly in a header. From this code we can deduce the following As a type, struct ParameterDefinition has at least three members. The first member is of a type that can hold either a set of at least 12 characters (but more likely at least 13 to include the terminating '\0' so the set can be treated as a string) or a pointer to a string. It could be an array of char or a pointer to char. The second member is of a type that is compatible with the k-pos variables (or perhaps they are macros or enums). The third member is probably of a floating point type. The array primaryParams contains exactly three elements of this structure, each of which is initialized with the corresponding set of data provided. If there are any other members of the struct, each is initialized to 0, NULL, or 0.0 as appropriate for its type. Remove del for email
From: Pat on 19 Apr 2008 17:13 Francis Glassborow wrote: > Pat wrote: >> I'm in the process of teaching myself C++ (with the help of several >> good books) so I can develop some DLL's for another application. >> >> Looking through an example of one of these, there's a line that >> defines a structure as follows: >> >> struct ParameterDefinition primaryParams[]= >> { >> {"x position =", kXpos, 1.0} >> {"y position =", kYpos, 2.0} >> {"z position =", kZpos, 0.0} >> }; >> >> >> None of the books I've been reviewing define a structure in this way >> (at least so far). So what is "ParameterDefinition"? A pointer? I >> assume it actually contains the code that defines this structure >> type. Is there a name for this way defining a structure? I'd like to >> read more about that. > > No, you have misunderstood. The above is NOT a definition of a struct. > struct ParameterDefinition is a type written in C form, C++ would just > use ParameterDefinition (it does not need the prefix 'struct' to tell > the compiler that the following is the name of a struct type. > > Now given that 'struct ParameterDefinition' is just a long winded name > for a type we can read the whole declaration/definition as: > > primaryParams is an array (size to be deduced from the provided > initialisers) of type ParameterDefinition which is to be initialised > with three sets of values. > > Compare this with the simpler but similar > > int array[] = {1, 2, 3}; Thanks. You're right. I removed the "struct" (so it just reads "ParameterDefinition primaryParams[]=") and it stilled compiled and ran fine. So that now makes sense (except now I'm going have to sort out what's C vs C++ !) The question now though is where is ParameterDefinition actually defined? It's definition is not shown in the source file I'm working with. I guess I need to start checking the files referenced in the headers. But as an academic exercise, I assume ParameterDefinition looks something like this? struct ParameterDefinition { char coordinateName[20]; double units; double coordinateValue; }; (BTW, there should have been commas after each structure element in my original example).
From: Jensen Somers on 19 Apr 2008 17:25 Pat wrote: > Francis Glassborow wrote: >> Pat wrote: >>> I'm in the process of teaching myself C++ (with the help of several >>> good books) so I can develop some DLL's for another application. >>> >>> Looking through an example of one of these, there's a line that >>> defines a structure as follows: >>> >>> struct ParameterDefinition primaryParams[]= >>> { >>> {"x position =", kXpos, 1.0} >>> {"y position =", kYpos, 2.0} >>> {"z position =", kZpos, 0.0} >>> }; >>> >>> >>> None of the books I've been reviewing define a structure in this way >>> (at least so far). So what is "ParameterDefinition"? A pointer? I >>> assume it actually contains the code that defines this structure >>> type. Is there a name for this way defining a structure? I'd like >>> to read more about that. >> >> No, you have misunderstood. The above is NOT a definition of a struct. >> struct ParameterDefinition is a type written in C form, C++ would just >> use ParameterDefinition (it does not need the prefix 'struct' to tell >> the compiler that the following is the name of a struct type. >> >> Now given that 'struct ParameterDefinition' is just a long winded name >> for a type we can read the whole declaration/definition as: >> >> primaryParams is an array (size to be deduced from the provided >> initialisers) of type ParameterDefinition which is to be initialised >> with three sets of values. >> >> Compare this with the simpler but similar >> >> int array[] = {1, 2, 3}; > > > Thanks. You're right. I removed the "struct" (so it just reads > "ParameterDefinition primaryParams[]=") and it stilled compiled and ran > fine. So that now makes sense (except now I'm going have to sort out > what's C vs C++ !) > > The question now though is where is ParameterDefinition actually > defined? It's definition is not shown in the source file I'm working > with. I guess I need to start checking the files referenced in the > headers. > > But as an academic exercise, I assume ParameterDefinition looks > something like this? > > struct ParameterDefinition > { > char coordinateName[20]; > double units; > double coordinateValue; > }; > Correct > > > (BTW, there should have been commas after each structure element in my > original example). > - Jensen
|
Next
|
Last
Pages: 1 2 3 Prev: Idea: Working past compile failures (TryCompileOnFailure-Block) Next: map of classes |