🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: be.comp.programming
Article #4984

Re: [C++] function overloading en typedef

#4984
From: Dominique Devriese
Date: Wed, 28 May 2003 12:59
45 lines
2449 bytes
Johan Vervloet writes:

  Johan> Hallo, Ik zit met een probleem gelijkaardig aan het volgende
  Johan> :

  Johan> Stel ik heb een klasse GekleurdeInt, en ik wil die als volgt
  Johan> definieren :

  Johan>         typedef int Kleur; // proper niwaar :-)

  Johan>         class GekleurdeInt { public:
  Johan>                 GekleurdeInt( int i ); GekleurdeInt( Kleur k
  Johan>                 );
  Johan>         /* enz */ };

  Johan> Dit werkt dus niet, aangezien int en Kleur voor de compiler
  Johan> van hetzelfde datatype zijn.

  Johan> Bestaat er hiervoor een mooie oplossing, zonder hiervoor een
  Johan> hele nieuwe klasse Kleur te moeten maken ?

het zgn. "Named Constructor Idiom" [1] kan hier mss helpen ?

Kort samengevat wordt dat dus:

typedef int Kleur;

class GekleurdeInt
{
public:
        GekleurdeInt( int i, Kleur k );
        static GekleurdeInt fromInt( int i );
        static GekleurdeInt fromKleur( Kleur k );
};

sjuus
domi

Footnotes: 
[1]  http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.8

-- 
For he is the lambda and xdelta, and every opening parenthesis will be
closed at the end of all input.
(David Kastrup on alt.religion.emacs)
Technical Details
Message-ID: <87el2jns51.fsf@student.kuleuven.ac.be>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-01!sn-xit-09!supernews.com!newsfeed.news2me.com!newsfeed.icl.net!newsfeed.fjserv.net!proxad.net!nerim.net!aotearoa.belnet.be!naxos.belnet.be!news.belnet.be!not-for-mail
References: <3ed4a249.0@news.ruca.ua.ac.be>

Show Full Headers
Complete Article Headers
X-Google-Language: DUTCH,ASCII-7-bit
X-Google-Thread: fcea4,3077f069a49c0aca
X-Google-Attributes: gidfcea4,public
X-Google-ArrivalTime: 2003-05-28 05:58:08 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-01!sn-xit-09!supernews.com!newsfeed.news2me.com!newsfeed.icl.net!newsfeed.fjserv.net!proxad.net!nerim.net!aotearoa.belnet.be!naxos.belnet.be!news.belnet.be!not-for-mail
From: Dominique Devriese <dominique.devriese@student.kuleuven.ac.be>
Newsgroups: be.comp.programming
Subject: Re: [C++] function overloading en typedef
Date: 28 May 2003 14:59:54 +0200
Organization: KULeuvenNet
Lines: 45
Sender: domi@appel
Message-ID: <87el2jns51.fsf@student.kuleuven.ac.be>
References: <3ed4a249.0@news.ruca.ua.ac.be>
NNTP-Posting-Host: seven.kulnet.kuleuven.ac.be
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
X-Trace: naxos.belnet.be 1054126660 5822 134.58.127.12 (28 May 2003 12:57:40 GMT)
X-Complaints-To: abuse@belnet.be
NNTP-Posting-Date: Wed, 28 May 2003 12:57:40 +0000 (UTC)
User-Agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Portable Code)
Cache-Post-Path: seven.kulnet.kuleuven.ac.be!unknown@domi.kotnet.org
X-Cache: nntpcache 2.4.0b5 (see http://www.nntpcache.org/)