VoyForums
[ Show ]
Support VoyForums
[ Shrink ]
VoyForums Announcement: Programming and providing support for this service has been a labor of love since 1997. We are one of the few services online who values our users' privacy, and have never sold your information. We have even fought hard to defend your privacy in legal cases; however, we've done it with almost no financial support -- paying out of pocket to continue providing the service. Due to the issues imposed on us by advertisers, we also stopped hosting most ads on the forums many years ago. We hope you appreciate our efforts.

Show your support by donating any amount. (Note: We are still technically a for-profit company, so your contribution is not tax-deductible.) PayPal Acct: Feedback:

Donate to VoyForums (PayPal):

Login ] [ Contact Forum Admin ] [ Main index ] [ Post a new message ] [ Search | Check update time | Archives: 1 ]
Subject: Re: Template skilgreiningar


Author:
Hjálmtýr
[ Next Thread | Previous Thread | Next Message | Previous Message ]
Date Posted: 20:18:42 02/22/04 Sun
In reply to: Jóhann H. Gunnarsson 's message, "Template skilgreiningar" on 19:52:29 02/22/04 Sun

>Ég hef verið að reyna að búa til clasa sem er með
>struct inn í sér. Málið er að struct-ið inniheldur þau
>gildi sem klasinn er að sjá um að geyma.
>Hvernig get ég búið til template fyrir þennan clasa
>svo það "erfist" ofan í structið?
>S.s senda áfram týpuna sem klasinn er?
>
>S.s
>template
>class bla
> private:
> struct node
> { Item x[] .....}
>
>
>int main()
> bla(int) intKlasi = new bla()

Ég er ekki alveg viss um að ég skilji hvað vandamálið er, en ef þú skoðar t.d. Forrit 4.8 á bls. 156 sem hefur tengda lista útfærslu á stafla þá er klasinn STACK skilgreindur sem "template class" með tagbreytunni Item. Síðan er struct-ið node skilgreint inní honum og það notar tagbreytuna Item.

Ef þú býrð til stafla með "STACK<int> A(100);" þá eru hnútarnir sem verða búnir til með int-breytunni item. Ef þú notaðir hins vegar "STACK<Cat> B(100);", þá hefðu hnútarnir breytuna item af taginu Cat.

Svarar þetta spurningunni?

[ Next Thread | Previous Thread | Next Message | Previous Message ]

Replies:
Subject Author Date
Re: Template skilgreiningarNo name21:43:16 02/22/04 Sun


Post a message:
This forum requires an account to post.
[ Create Account ]
[ Login ]
[ Contact Forum Admin ]


Forum timezone: GMT+0
VF Version: 3.00b, ConfDB:
Before posting please read our privacy policy.
VoyForums(tm) is a Free Service from Voyager Info-Systems.
Copyright © 1998-2019 Voyager Info-Systems. All Rights Reserved.