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).


|