________________________________
From: sree <[email protected]>
To: [email protected]
Sent: Friday, 28 August, 2009 9:05:06 PM
Subject: Re: [c-prog] C++ overloading?
Hi thefirstrepairdad,
This happens because method overloading ( u used correct term) does not
distinguish two functions/methods only by return type. It is always based on
number or/and type of arguments. you need to change your function syntax.
How about making return type as void for both and passing DATA/ENTRY as
argument?
Thanks
Srinimand
On Thu, Aug 27, 2009 at 4:50 PM, thefirstrepairdad <mowgl...@gmail. com>wrote:
>
>
> 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);
>
I guess just passing the return-type to the function argument list should do,
struct DATA *initialize_ list(DATA) {
return ();
}
struct Entry *initialize_ list(Entry) {
return ();
}
>
>
>
[Non-text portions of this message have been removed]
Yahoo! recommends that you upgrade to the new and safer Internet Explorer
8. http://downloads.yahoo.com/in/internetexplorer/
[Non-text portions of this message have been removed]