Talk About Network

Google





Programming > C - C++ Learning > Re: A question ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 11 Topic 4120 of 4400
Post > Topic >>

Re: A question about structures

by Pat <pkelecy@[EMAIL PROTECTED] > Apr 19, 2008 at 05:13 PM

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




 11 Posts in Topic:
A question about structures
Pat <pkelecy@[EMAIL PR  2008-04-19 11:06:19 
Re: A question about structures
Francis Glassborow <fr  2008-04-19 16:20:42 
Re: A question about structures
Pat <pkelecy@[EMAIL PR  2008-04-19 17:13:44 
Re: A question about structures
Jensen Somers <jensen.  2008-04-19 23:25:38 
Re: A question about structures
Pat <pkelecy@[EMAIL PR  2008-04-19 19:38:17 
Re: A question about structures
Barry Schwarz <schwarz  2008-04-19 10:55:40 
Re: A question about structures
Pat <pkelecy@[EMAIL PR  2008-04-19 17:30:48 
Re: A question about structures
Richard Heathfield <rj  2008-04-19 22:10:45 
Re: A question about structures
Pat <pkelecy@[EMAIL PR  2008-04-19 19:38:01 
Re: A question about structures
Jensen Somers <jensen.  2008-04-20 13:35:43 
Re: A question about structures
Pat <pkelecy@[EMAIL PR  2008-04-20 11:09:30 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
localhost-V2008-12-19 Wed Jan 7 12:14:42 PST 2009.