small typedef question

Sometimes the makers of tutorials give an example to purposefully trick the reader. This leads to them learning a distinction between two things. This example is very tricky, because being that a class is a type, you can typedef class, but for example can you typedef the identifier, which is supposedly also a type. Heres the example

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
#include <iostream>
#include <string>
using namespace std;

typedef struct Student;
typedef class Country;

struct Student
{
	string FirstName;
	string LastName;
};

typedef struct _Empl
{
	string FullName;
	double HourlySalary;
}Employee;

class Country
{
	string Name;
	string Capital;
	string Code;
};

typedef enum EmplStatus { esFullTime, esPartTime, esContractor };
typedef Student *PStudent;
typedef Country *PCountry;

int main()
{
	Student pupil;
	Country pais;
	EmplStatus emplst;
	PStudent ptrStd = new Student;
	PCountry pPais = new Country;

	return 0;
}



As you can see struct and class were typedefined, but it seems the type was never used, because when Student and Country were initialized there still used type struct and class. So, can I assume that those new typedefs were never used, and that if we wanted them to be used we could have declared class Student like this (Student Student). Yes I know that sounds wierd, but later you can see the type PStudent is defined as a pointer to type Student. And knowing you cant point to an identifer of struct, I must assume that the earlier declarations of
typedef struct Student;
typedef class Country;
were never used.

Plz any help would be greatly appreciated, if i am wrong let me know.


Last edited on
I doubt if your example code compiles good.

the lines:

typedef class Student;
typedef class Countly;

would complain with a compiler error as there is only a representation but no name.

The right form would be

typedef class Studnet {

// ..
// ..
// ..
// blah blah definition

} StudentType;


And other typedef is right coded:

typedef struct _Empl
{
string FullName;
double HourlySalary;
}Employee;


The whole example is error-prone and would not compile.

Check it out. Good luck :)
Topic archived. No new replies allowed.