cpp2html 0.1-alpha © 2002 Andrea Leofreddi. To get the source click here

// 7.1: strutture
#include <iostream>

using namespace std;

// definisco il tipo Prova (struct)
struct Prova {
	int dato;
	char mychar;
	char *ptr;
};

// definisco il tipo Coordinate
struct Coordinate {
	float x;
	float y;
};

int main() {
	Prova a; // istanzio l'instanza a di tipo Prova

	a.dato = 4;
	a.mychar = 'j';
	a.ptr = NULL;

	Coordinate b; // istanzio l'instanza b di tipo Coordinate

	b.x = 4.0f;
	b.y = 9.5f;

	Coordinate *c(&b); // puntatore all'istanza b
	// si poteva anche scrivere come
	// Coordinate *c = &b;

	// c.x = 3.0f; // ERRORE: c e' di tipo Coordinate *
	c->x = 3.0f; // corretto, adesso b.x e' 3.0f
}