473,395 Members | 1,502 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,395 software developers and data experts.

Is it possible... (defining new particular operators)

I wrote a simple new template class for a C++ project operating on
quaternions.

I would like to define 2 new particular operators

The first I would like to be (*) for cross product (vector product
between 2 quaternions)
The second Iwould like to be (.) for dot product (scalar product between
2 quaternions)

Is it possible?

I declared normally in the class Quaternion:

Quaternion<Toperator(*)(const Quaternion<T>& q) const;
Quaternion<Toperator(.)(const Quaternion<T>& q) const;

But I get the following errors
15 ..\Quaternion.h expected identifier before '(' token

etc etc...

Aspidus
Apr 28 '07 #1
3 1260
Aspidus wrote:
I wrote a simple new template class for a C++ project operating on
quaternions.

I would like to define 2 new particular operators

The first I would like to be (*) for cross product (vector product
between 2 quaternions)
The second Iwould like to be (.) for dot product (scalar product between
2 quaternions)

Is it possible?
The first one is, the second one isn't. Operator. can't be overloaded, and
it wouln't be a good thing anyway. It just would do something entirely
different from what you would expect from operator.
I declared normally in the class Quaternion:

Quaternion<Toperator(*)(const Quaternion<T>& q) const;
Quaternion<Toperator*(const Quaternion<T>& q) const;

I'd recommend implementing it as a non-member, and you might want to
implement it in terms of operator*= (which you would have to implement
too).
Quaternion<Toperator(.)(const Quaternion<T>& q) const;
Not possible.

Apr 28 '07 #2
On Apr 28, 7:29 pm, Rolf Magnus <ramag...@t-online.dewrote:
Aspidus wrote:
I wrote a simple new template class for a C++ project operating on
quaternions.
I would like to define 2 new particular operators
The first I would like to be (*) for cross product (vector product
between 2 quaternions)
The second Iwould like to be (.) for dot product (scalar product between
2 quaternions)
Is it possible?

The first one is, the second one isn't. Operator. can't be overloaded, and
it wouln't be a good thing anyway. It just would do something entirely
different from what you would expect from operator.
I declared normally in the class Quaternion:
Quaternion<Toperator(*)(const Quaternion<T>& q) const;

Quaternion<Toperator*(const Quaternion<T>& q) const;

I'd recommend implementing it as a non-member, and you might want to
implement it in terms of operator*= (which you would have to implement
too).
Quaternion<Toperator(.)(const Quaternion<T>& q) const;

Not possible.
you can overload another operator for this purpose: bitwise or for
example:
Quaternion<T>::Quaternion<Toperator | (const Quaternion<T>& q) const;

Apr 28 '07 #3

Good idea! I could use bitwise or | for the vector product and the
normal operator of multiplication for the scalar product.

So the point is that I cannot define new operators, I can just overload
the pre-existents.

Thank you all.

Aspidus

>
you can overload another operator for this purpose: bitwise or for
example:
Quaternion<T>::Quaternion<Toperator | (const Quaternion<T>& q) const;
Apr 29 '07 #4

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

Similar topics

10
by: Joe Laughlin | last post by:
I'm sure there's a fairly easy answer for this... but how can I define a new type with range checking? Example: I want to define a new type that's like a double, except that you can only give...
23
by: John | last post by:
Last year, I remember finding a web page describing how to pass the name of a file to another web page, and have that web page load that image file. Now, I can't find my record of that (it was...
40
by: Ron Adam | last post by:
After considering several alternatives and trying out a few ideas with a modified list object Bengt Richter posted, (Thank You), I think I've found a way to make slice operation (especially far end...
92
by: Raghavendra R A V, CSS India | last post by:
hie.. Do any one knows how to write a C program without using the conditional statements if, for, while, do, switch, goto and even condotional statements ? It would be a great help for me if...
23
by: Ken Turkowski | last post by:
The construct (void*)(((long)ptr + 3) & ~3) worked well until now to enforce alignment of the pointer to long boundaries. However, now VC++ warns about it, undoubtedly to help things work on 64...
1
by: Frederick Gotham | last post by:
If we want to copy an array of POD's, we can simply do: SomePODType src = { ... }, dest; memcpy(&dest,&src,sizeof dest); We can assume that this method is definitely faster than (if not at...
26
by: Cliff Williams | last post by:
Can someone explain the pros/cons of these different ways of creating a class? // 1 function myclass() { this.foo1 = function() {...} } // 2a
6
by: alan | last post by:
I'm creating a sort-of "wrapper" class which (partly) acts like a variable. Something like: template<class t> class cell{ t curval; public: /*public for debugging only - will be private in...
16
by: blaze77 | last post by:
Hi, I'm somewhat of a power user in excel and a newbie to Access though the possibilities are exciting me :-) I am trying to create a tool in Access to replace an existing tool in Excel. My...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.