🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: att.lang.c++
Article #58

Re: operator overloading syntax question

#58
From: Roman Fietze
Date: Tue, 10 Apr 2001 06:36
66 lines
2350 bytes
Hello,

God_Of_Pain <silicontao_roy@technologist.com> writes:

> ...
> Any help would be great.
> ...

I would say that is somewhat overkill. First of all I would store the
port bits in one BYTE variable (typedef unsigned char BYTE; class
TPortMap ... private: BYTE PortBits; ...) inside your class. Setting
single bits could probably be done like this:

void TPortMap::SetBits(BYTE bits)
{
	PortBits |= bits;
	WritePortBits();
}

void TPortMap::SetBit(unsigned short i)
{
	PortBits |= (1U << i);
	WritePortBits();
}


Querying could be done like

BYTE TPortMap::GetBits() const
{
	return (PortBits);
}

bool TPortMap::GetBit(unsigned short i) const
{
	return (PortBits & (1U << i));
}


and you operators could be something like

bool operator[] (unsigned short i) const
{
	return (GetBit(i));
}


void operator= (BYTE bits)
{
	SetBits(bits);
}



What would be nice is something like

MyPort[5] = true;

but that's not doable this way.


Roman

-- 
Roman Fietze (Mail Code 6)     roman.fietze@de.heidelberg.com
Heidelberg Digital Finishing GmbH, Germany     DDF-T SWEC ESW
Technical Details
Message-ID: <rc64rvx2rcm.fsf@kagcpd05.muh.de.heidelberg.com>
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!logbridge.uoregon.edu!news.stealth.net!news.uni-stuttgart.de!news.ruhr-uni-bochum.de!news.tmr.net!news.vew-telnet.net!feeder00.news.de.uu.net!news.netuse.de!news.hdpp.de!muhws20.muh.de.heidelberg.com!nobody
References: <otkA6.8297$%B2.1110673@news1.telusplanet.net>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10d4ba,94ced0dda0a89aaa
X-Google-Attributes: gid10d4ba,public
X-Google-Thread: 109fba,94ced0dda0a89aaa
X-Google-Attributes: gid109fba,public
X-Google-Thread: fff06,94ced0dda0a89aaa
X-Google-Attributes: gidfff06,public
X-Google-ArrivalTime: 2001-04-10 01:16:05 PST
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!logbridge.uoregon.edu!news.stealth.net!news.uni-stuttgart.de!news.ruhr-uni-bochum.de!news.tmr.net!news.vew-telnet.net!feeder00.news.de.uu.net!news.netuse.de!news.hdpp.de!muhws20.muh.de.heidelberg.com!nobody
From: Roman Fietze <fietze@kagcpd05.muh.de.heidelberg.com>
Newsgroups: att.lang.c++,comp.lang.c++,comp.os.linux.embedded
Subject: Re: operator overloading syntax question
Date: 10 Apr 2001 08:36:57 +0200
Organization: Heidelberg Digital Finishing GmbH
Lines: 66
Message-ID: <rc64rvx2rcm.fsf@kagcpd05.muh.de.heidelberg.com>
References: <otkA6.8297$%B2.1110673@news1.telusplanet.net>
NNTP-Posting-Host: 10.53.116.17
X-Trace: news.hdpp.de 986889604 23074 10.53.116.17 (10 Apr 2001 08:00:04 GMT)
X-Complaints-To: abuse@news.hdpp.de
NNTP-Posting-Date: 10 Apr 2001 08:00:04 GMT
X-Newsreader: Gnus v5.7/Emacs 20.7