Re: Passing Structure to a function

From: Jon Bell (jtbellq2f_at_presby.edu)
Date: 11/12/03


Date: Wed, 12 Nov 2003 15:22:14 +0000 (UTC)

In article <kwjsb.6709$Bv6.2038122@news1.epix.net>,
kazack <kazack@talon.net> wrote:
>
>struct data
>{
>float amount;
>string fname;
>string lname;
>} rec;

This does two things:

(1) It defines a data type named 'data', as a struct with the specified
fields.

(2) It declares a variable named 'rec', of type 'data'.

The usual practice in C++ is to separate the two actions:

struct data
{
   float amount;
   string fname;
   string lname;
};

data rec;

This is mainly because data types are usually defined outside of any
function, so they are available in any function in the current scope,
whereas variables are usually declared inside a function, so they are
directly usable only within that function.

To put it another way, types are usually defined globally, but variables
are usually defined locally.

>//prototype
>void print_rec(struct data x);

The "struct" keyword is completely unnecesary here, in C++. C++ compilers
accept it only for backward compatibility with C.

-- 
Jon Bell <jtbellap8@presby.edu>                     Presbyterian College
Dept. of Physics and Computer Science        Clinton, South Carolina USA


Relevant Pages

  • Re: MDX calculated member
    ... Can the Names of the members of [Job Begin Rec Date].Members, [Job Rec ... End Day].Members and.Members be cast to the Date data type? ... Deepak Puri ...
    (microsoft.public.sqlserver.olap)
  • any = long sequence .... how???
    ... who i get a sequence of longs in one any data type? ... typedef sequencelongSequence; ... string name; ...
    (comp.lang.java.corba)