473,498 Members | 1,713 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Access a class as if it were POD

I've got a requirement to implement a C++ class which should be usable
as if it were an unsigned long:

Foo my_foo;

my_foo = 1;

if (my_foo < 1000)
{
// do this
}

etc.

Is there a simple way I can do this with references, or do I need to
overload every operator under the sun?

--
Simon Elliott http://www.ctsn.co.uk
Jul 22 '05 #1
3 1011
"Simon Elliott" <Simon at ctsn.co.uk> wrote in message
news:41***********************@news.gradwell.net.. .
I've got a requirement to implement a C++ class which should be usable
as if it were an unsigned long:

Foo my_foo;

my_foo = 1;

if (my_foo < 1000)
{
// do this
}

etc.

Is there a simple way I can do this
Yes.
with references,
You don't need references (but you can use them if you like).
or do I need to
overload every operator under the sun?


No.

Hints:

Foo::Foo(unsigned long){}
Foo::operator unsigned long(){}

This may or may not be 'cheating', depending upon more
specific defintion of your requirements.

-Mike

Jul 22 '05 #2
On 08/10/2004, Mike Wahler wrote:
Hints:

Foo::Foo(unsigned long){}
Foo::operator unsigned long(){}

This may or may not be 'cheating', depending upon more
specific defintion of your requirements.


Thanks for this. I'd expect I'll also need a
Foo::operator=(unsigned long){}
--
Simon Elliott http://www.ctsn.co.uk
Jul 22 '05 #3

"Simon Elliott" <Simon at ctsn.co.uk> wrote in message
news:41***********************@news.gradwell.net.. .
On 08/10/2004, Mike Wahler wrote:
Hints:

Foo::Foo(unsigned long){}
Foo::operator unsigned long(){}

This may or may not be 'cheating', depending upon more
specific defintion of your requirements.


Thanks for this. I'd expect I'll also need a
Foo::operator=(unsigned long){}


Not necessarily. Remember what a default compiler synthesized
assignment operator will do. It's issues like this that caused
my 'possible cheat' remark above -- we're simply delegating the work
to a built-in type, and depending upon already defined operations.
IOW a 'wrapper'.

-Mike
Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
3930
by: CoolPint | last post by:
I read in books that nested class cannot access private members of nesting class and vice versa unless they are made friends. Somehow, my compiler is letting my nested class member functions access...
6
4707
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
9
2675
by: MacDermott | last post by:
I have an Access MDB which instantiates a class in a custom DLL, manipulates it for a while, then sets it equal nothing. The MDB does other things,too, and generally behaves itself as desired....
49
14276
by: Yannick Turgeon | last post by:
Hello, We are in the process of examining our current main application. We have to do some major changes and, in the process, are questionning/validating the use of MS Access as front-end. The...
55
3484
by: AnandaSim | last post by:
I just had a google through this NG but have not seen mention of Erik Rucker's blog entry and the new Jet: http://blogs.msdn.com/access/archive/2005/10/05/477549.aspx mentioned by Mike...
0
3157
by: Andrew Dowding | last post by:
Hi Everybody, I have been looking at problems with my Windows Forms C# application and it's little Jet 4 (Access) database for the last few days. The Windows Forms app implements a facade and...
7
1892
by: tron.thomas | last post by:
Please consider the following code: class Abstract { public: virtual ~Abstract() {} virtual void Method() = 0; }; class Concrete : public virtual Abstract
4
1119
by: Vivek Sharma | last post by:
Hi, I have a form in a windows application. In that form I have declared the public property InvoiceNo. I am trying to access this property from the other form. In the other form I declared...
5
1756
by: psp | last post by:
I'm really puzzled why this is allowed by the c++ compiler: class C { public: void setNumber( int y ) { m_y = y; } void printNumber() const { cout << "m_y= " << m_y << endl; } void copyInt(C...
8
4135
by: Wayne | last post by:
I have had a problem for some time with several databases and figure there must be a common underlying cause. Sometimes when I open a database, nothing appears to happen, but an .ldb file gets...
0
7002
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7165
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7379
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4588
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3093
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3081
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1417
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
290
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.