473,388 Members | 1,220 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Class overoaded operators

I want to write Exponent class that overoads the ^ operator so it can be used to perform exponential notation. For instance if you use the statement
int iResult = 10 ^ 3;, the iResult variable should be assigned a value of 1000. How can I write that?
Jul 1 '08 #1
4 1296
weaknessforcats
9,208 Expert Mod 8TB
Hmmm. Please refresh my memory and tell me what the ^ operator does.
Jul 1 '08 #2
JosAH
11,448 Expert 8TB
Hmmm. Please refresh my memory and tell me what the ^ operator does.
It bitwise exclusive or's both of its integral operands. AFAICT you can't overload an
operator for two primitives (such as int).

kind regards,

Jos
Jul 1 '08 #3
Banfa
9,065 Expert Mod 8TB
Not to mention it is very poor practice in any class to overload any arithmetic operator to a different arithmetic function. It is bound to cause confusion, mis-use and hours of debugging.
Jul 2 '08 #4
weaknessforcats
9,208 Expert Mod 8TB
Quote:
Originally Posted by weaknessforcats
Hmmm. Please refresh my memory and tell me what the ^ operator does.


It bitwise exclusive or's both of its integral operands. AFAICT you can't overload an
operator for two primitives (such as int).
Hook, line and sinker. The OP was to answer this. Banfa has the correct take on this.
Jul 2 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Ryan Mitchley | last post by:
Hi I have a rather complicated class for performing matrix operations using complex arithmetic. I have written two classes, CComplexMatrix and CComplexMatrixTemp, and have been attempting to...
3
by: Pierre Espenan | last post by:
A have a long integer class. The built integer type within a conditional statement returns bool false for int i=0 and bool true for any other non zero value. I want my long integer class to have...
11
by: Robert Sturzenegger | last post by:
We had a strange problem in a large project with the use of a string class in a static instance of a struct. I managed to reproduce the exactly same problem in a very short program (see below)....
7
by: Jef Driesen | last post by:
Suppose I have an abstract base class that looks like this: template <typename T> class base { public: // Typedefs typedef double value_type; typedef std::size_t size_type; public: //...
7
by: Riku Jarvinen | last post by:
Hello everyone, I have a logging class which writes program outputs to the logfile. The class works fine as long as only C++ native data types are considered. The problem is that I have a...
13
by: olanglois | last post by:
Hi, I am trying to derive a new class that will add new functions but no new data members and the base class has overloaded operators (+,-,+=,-=,etc...) returning either (Base &) or (const Base)...
14
by: lovecreatesbea... | last post by:
Could you tell me how many class members the C++ language synthesizes for a class type? Which members in a class aren't derived from parent classes? I have read the book The C++ Programming...
3
by: =?gb2312?B?wfXquw==?= | last post by:
Hi, folks, I'm running into a question as below: template<typename T> class A { private: T _a; public: A(T t): _a(t) { }
5
by: Harinezumi | last post by:
Hello, I need help with the design of a serialization template base class. The idea is that any class derived from this template base class would only need to implement the input and output...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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
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
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...

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.