1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
In this section we'll discuss an important difference between bf(C) and
bf(C++) structs and (member) functions. In bf(C) it is common to define
several functions to process a tt(struct), which then require a pointer to the
tt(struct) as one of their arguments. An imaginary bf(C) header file showing
this concept is:
verb( /* definition of a struct PERSON This is C */
typedef struct
{
char name[80];
char address[80];
} PERSON;
/* some functions to manipulate PERSON structs */
/* initialize fields with a name and address */
void initialize(PERSON *p, char const *nm,
char const *adr);
/* print information */
void print(PERSON const *p);
/* etc.. */)
In bf(C++), the declarations of the involved functions are put inside
the definition of the tt(struct) or tt(class). The argument denoting
which tt(struct) is involved is no longer needed.
verb( class Person
{
char d_name[80];
char d_address[80];
public:
void initialize(char const *nm, char const *adr);
void print();
// etc..
};)
In bf(C++) the tt(struct) parameter is not used. A bf(C) function call
such as:
verb( PERSON x;
initialize(&x, "some name", "some address");)
becomes in bf(C++):
verb( Person x;
x.initialize("some name", "some address");)
|