From: "Brian MacBride" Newsgroups: comp.os.msdos.djgpp References: <841d86$gg4 AT chronicle DOT concentric DOT net> Subject: Re: Structs Lines: 70 Organization: Signal Computing Service Ltd. MIME-Version: 1.0 Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2919.6600 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6600 Message-ID: Date: Sat, 25 Dec 1999 06:37:31 GMT NNTP-Posting-Host: 204.210.106.78 X-Complaints-To: abuse AT rr DOT com X-Trace: hnlnewsr1.hawaii.rr.com 946103851 204.210.106.78 (Fri, 24 Dec 1999 20:37:31 HST) NNTP-Posting-Date: Fri, 24 Dec 1999 20:37:31 HST To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com "Requiem" wrote in message news:841d86$gg4 AT chronicle DOT concentric DOT net... > How can I link two different structs to the same function, without declaring > the function in both structs. > > for example > > int query_gold(); > > struct foo { > int la; > int pe; > } > > struct foo2 { > int la; > int pe; > } > > foo->query_gold(); > foo2->query_gold(); > > Thanks > > Requiem > iraemortis AT subdimension DOT com > > Consider... struct bar { int query_gold () { return 2; } }; struct foo : public bar { int la; int pe; }; struct foo2 : public bar { int la; int pe; }; #include int main () { cout << foo ().query_gold () << endl; cout << foo2 ().query_gold () << endl; return 0; } /* Yields... 2 2 */ Is that what you wanted?? Regards Brian