September 1998
Intermediate to advanced
848 pages
20h 13m
English
After you declare a structure or union having a tag, you can use the tag as a type name in C++:
struct duo
{
int a;
int b;
};
struct duo m; /* valid C, C++ */
duo n; /* invalid C, valid C++ */
As a result, a structure name can conflict with a variable name. For example, the following program compiles as a C program, but it fails as a C++ program because C++ interprets the duo in the printf() statement as a structure type rather than as the external variable:
#include <stdio.h>
float duo = 100.3;
int main(void)
{
struct duo { int a; int b;};
struct duo y = { 2, 4};
printf ("%f\n", duo); /* ok in C, not in C++ */
return 0;
}
In C and in C++, you can declare one structure inside another:
struct box { struct point {int ...Read now
Unlock full access