Re: Passing Structure to a function
From: Jon Bell (jtbellq2f_at_presby.edu)
Date: 11/12/03
- Next message: Jon Bell: "Re: beginner string question"
- Previous message: tom_usenet: "Re: Resume the computation after an exception"
- In reply to: kazack: "Passing Structure to a function"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: Jon Bell: "Re: beginner string question"
- Previous message: tom_usenet: "Re: Resume the computation after an exception"
- In reply to: kazack: "Passing Structure to a function"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|