473,799 Members | 2,840 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How should a number-class look like?

What is wrong with the following? Why doesn't it compile?

template<int f, class me, typename ValType=int>
class Fm
{
protected:
ValType v;
public:
me& operator+=(cons t me& o) {v=((me*)this)->operator+(o) ; return *(me*)this;}
me& operator*=(cons t me& o) {v=((me*)this)->operator*(o) ; return *(me*)this;}
me& operator-=(const me& o) {v=((me*)this)->operator-(o); return *(me*)this;}
me& operator/=(const me& o) {v=((me*)this)->operator/(o); return *(me*)this;}
friend me operator+(const me& a, const me& b) {return me(a.operator+( b));}
friend me operator*(const me& a, const me& b) {return me(a.operator*( b));}
friend me operator-(const me& a, const me& b) {return me(a.operator-(b));}
friend me operator/(const me& a, const me& b) {return me(a.operator/(b));}
};

class F0m : public Fm<0,F0m>
{
friend class Fm<0,F0m>;
int operator*(const F0m& o) const {return v*o.v;}
int operator/(const F0m& o) const {return v/o.v;}
int operator+(const F0m& o) const {return (o.v==v ? 0 : v+o.v);}
int operator-(const F0m& o) const {return (o.v==-v ? 0 : v-o.v);}
public:
F0m() {}
F0m(int n) {n%=3; v=(n>1 ? -1 : n);}
F0m& operator=(int n) {n%=3; v=(n>1 ? -1 : n); return *this;}
};

int main(...){
F0m n,p,z;
n=-1;
p=4;
z=234;
p=n*n;
n*=p;
z*=n;
z=n+p;
z=p-p;
n=p+p;
n+=z;
p-=z;
p=n/n;
n/=p;
/* assert(n!=p && p!=z && z!=n);*/
}
--
Better send the eMails to netscape.net, as to
evade useless burthening of my provider's /dev/null...

P
Jan 4 '07 #1
2 1306
Piotr Sawuk wrote:
What is wrong with the following? Why doesn't it compile?
What errors are you getting?
>
template<int f, class me, typename ValType=int>
class Fm
{
protected:
ValType v;
public:
me& operator+=(cons t me& o) {v=((me*)this)->operator+(o) ; return *(me*)this;}
me& operator*=(cons t me& o) {v=((me*)this)->operator*(o) ; return *(me*)this;}
me& operator-=(const me& o) {v=((me*)this)->operator-(o); return *(me*)this;}
me& operator/=(const me& o) {v=((me*)this)->operator/(o); return *(me*)this;}
friend me operator+(const me& a, const me& b) {return me(a.operator+( b));}
friend me operator*(const me& a, const me& b) {return me(a.operator*( b));}
friend me operator-(const me& a, const me& b) {return me(a.operator-(b));}
friend me operator/(const me& a, const me& b) {return me(a.operator/(b));}
};

class F0m : public Fm<0,F0m>
{
friend class Fm<0,F0m>;
int operator*(const F0m& o) const {return v*o.v;}
int operator/(const F0m& o) const {return v/o.v;}
int operator+(const F0m& o) const {return (o.v==v ? 0 : v+o.v);}
int operator-(const F0m& o) const {return (o.v==-v ? 0 : v-o.v);}
public:
F0m() {}
F0m(int n) {n%=3; v=(n>1 ? -1 : n);}
F0m& operator=(int n) {n%=3; v=(n>1 ? -1 : n); return *this;}
};

int main(...){
F0m n,p,z;
n=-1;
p=4;
z=234;
p=n*n;
n*=p;
z*=n;
z=n+p;
z=p-p;
n=p+p;
n+=z;
p-=z;
p=n/n;
n/=p;
/* assert(n!=p && p!=z && z!=n);*/
}
Jan 4 '07 #2
Piotr Sawuk wrote:
What is wrong with the following? Why doesn't it compile?

template<int f, class me, typename ValType=int>
class Fm
{
protected:
ValType v;
public:
me& operator+=(cons t me& o) {v=((me*)this)->operator+(o) ; return *(me*)this;}
me& operator*=(cons t me& o) {v=((me*)this)->operator*(o) ; return *(me*)this;}
me& operator-=(const me& o) {v=((me*)this)->operator-(o); return *(me*)this;}
me& operator/=(const me& o) {v=((me*)this)->operator/(o); return *(me*)this;}
friend me operator+(const me& a, const me& b) {return me(a.operator+( b));}
friend me operator*(const me& a, const me& b) {return me(a.operator*( b));}
friend me operator-(const me& a, const me& b) {return me(a.operator-(b));}
friend me operator/(const me& a, const me& b) {return me(a.operator/(b));}
};

class F0m : public Fm<0,F0m>
{
friend class Fm<0,F0m>;
int operator*(const F0m& o) const {return v*o.v;}
int operator/(const F0m& o) const {return v/o.v;}
int operator+(const F0m& o) const {return (o.v==v ? 0 : v+o.v);}
int operator-(const F0m& o) const {return (o.v==-v ? 0 : v-o.v);}
Remember that name look up happens before access check. Simply by making
the above overloaded operators private doesn't mean the compile won't
have a hard time to compare those with other candidates.
public:
F0m() {}
F0m(int n) {n%=3; v=(n>1 ? -1 : n);}
F0m& operator=(int n) {n%=3; v=(n>1 ? -1 : n); return *this;}
};

int main(...){
F0m n,p,z;
n=-1;
p=4;
z=234;
p=n*n;
n*=p;
z*=n;
z=n+p;
z=p-p;
n=p+p;
n+=z;
p-=z;
p=n/n;
n/=p;
/* assert(n!=p && p!=z && z!=n);*/
}

Regards,
Ben
Jan 4 '07 #3

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

Similar topics

21
43077
by: Gavin | last post by:
Hi, I'm a newbie to programming of any kind. I have posted this to other groups in a hope to get a response from anyone. Can any one tell me how to make my VB program read the Bios serial number (or would HDD be better, or both?) and put that info into VB prog so the program won't work on another computer. My program uses an MSAccess table. Much appreciated if you can help! Thanks
11
7164
by: don | last post by:
Ok, this is a homework assignment, but can you help me out anyway...... I need a routine for figuring out if a number inputted by the user is a prime number or not...... all I'm asking for is Not the exact code ( well maybe a little) but the logic or algorithm to tell whether or not a number is prime....
13
6543
by: Ron | last post by:
Hi all I'm deciding whether to use the PK also as an account number, invoice number, transaction number, etc that the user will see for the respective files. I understand that sometimes a number will be missing, which is not a problem for my purposes I don't think, but how would it be negative? Can randomly created PK autonumber fields be negative? Any way for a PK, autonumbered, *incremented* to be negative? TIA
1
5421
by: Scott269 | last post by:
So I've got an old MS Works database I imported into Access. I needed a primary key so I created a record number field that was just the record number I manually inserted when I entered it in the database so I could sort the records by the date at which they were entered. Well now I've deleted some of those records so its of course causing gaps in the records. The record number in Access no longer matches my record number that I...
13
12760
by: Kishor | last post by:
Hi Friends Please help me to write a C program to find the 5th (fifth) root of a given number. Ex:(1) Input : 32 Output : 5th root of 32 is 2 Ex:(1) Input : 243 Output : 5th root of 243 is 3 Click here : www.c4swimmers.esmartguy.com to Test Your C Programming Strengths.
16
12082
by: Leon | last post by:
I need a program that generate 5 non-duplicates random number between 1-10 as string values store in an array. Do anybody know of any good books or websites that explain how to generator random numbers using asp.net? I know about the random namespace within .net, but I need a reference to some code that do the similar stated function above. Plus If you have any coding practice ideas for the above defined project please share them.
19
4455
by: gk245 | last post by:
Trying to write a program that will figure out if a number is perfect or not. Here is my logic: 1) Read in the number 2) Split it up (number - 1) 3) Put all the split up numbers into an array 4) Figure out if the original number is evenly divisible by any of the numbers in the array.
4
5227
by: SweetLeftFoot | last post by:
Hello, i have designed some code that works out the first 250 prime numbers and prints them to the screen. However i need to implement 2 functions, one of which returns a 1 if the number is a prime and 0 if it isn't. I have spent ages just getting this code to work and i'm worried i need to rip it to bit to get this function to work ! The function is: int prime(int number) here is my code so far: #include...
4
10591
by: fatimahtaher | last post by:
Hi, I am supposed to create a program that generates a random number and then asks the user to guess the number (1-100). The program tells the user if he guessed too high or too low. If he guessed right, it asks the user is he/she wants to play again. If the answer is yes, it generates a random number and asks the user to guess the number again. The user can exit if he enters 0. I have created the following code so far but it does not work....
5
2539
by: silversnake | last post by:
I'm trying to write a program that take a input number and prints if is a prime numbers but is not working for instance, it says that 4 is prime while 5 is not. can anyone see what the problem is . thanks in advance #include <stdio.h> #include <math.h> #define TRUE 1; #define FALSE 0;
0
9687
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9541
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10251
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9072
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7564
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4139
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 we have to send another system
2
3759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2938
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.