Hi all,
I built a set of routines to manage linked lists and used overloading (I think
that's the correct terminology for what I've done) to allow calling the "same"
function using different data types.
Here's an example of what works:
extern void dump_list(FILE *, DATA *llist);
extern void dump_list(FILE *, ENTRY *llist);
extern void dump_list(FILE *, const DATA *llist, long int count);
extern void dump_list(FILE *, const ENTRY *llist, long int count);
...
void dump_list(FILE *fp, struct DATA *llist)
{
dump_list(fp, (struct DATA *)llist, 0L);
}
void dump_list(FILE *fp, struct ENTRY *llist)
{
dump_list(fp, llist, 0L);
}
void dump_list(FILE * fp, const DATA *llist, long int count)
{
struct DATA *tlist = (struct DATA *)llist;
struct DATA *plist = (struct DATA *)NULL;
long int iter = 0L;
...
}
void dump_list(FILE * fp, const ENTRY *llist, long int count)
{
struct ENTRY *tlist = (struct ENTRY *)llist;
struct ENTRY *plist = (struct ENTRY *)NULL;
long int iter = 0L;
...
}
But if I try to initialize a list, and return the appropriate data type, thusly:
extern struct DATA *initialize_list(void);
extern struct ENTRY *initialize_list(void);
and call it with
struct DATA *Dlist = initialize_list();
or
struct ENTRY *Elist = initialize_list();
I get errors saying:
"new declaration 'ENTRY* initialize_list()'"
"ambiguates old declaration 'DATA* initialize_list()'"
I assume because this function has no arguments, it can't determine which
version to use? Is there a way to do this? Do I need to pass an unused argument
to "set" the data type and just ignore it? As:
extern struct DATA *initialize_list(const DATA *llist);
extern struct ENTRY *initialize_list(const ENTRY *llist);
Thank you,
~Rick