I have a struct defined as the following:
typedef struct {
string foo;
} A, B;
I also have a set of functions as follows:
void Init(A *p) {
p->foo;
}
void Init(B *p) {
p->foo;
}
The gcc complains that Init is being redefined. Can I simply delete the second Init function? Is A the same type as B?
Yes, A and B are
essentiallyjust different aliases to the same type.I think the code would be more clear if you give a name to the struct itself, and define
Initas a function taking a pointer to the struct:It’s just personal preference however.