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

A

Aspidus

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<T> operator(*)(const Quaternion<T>& q) const;
Quaternion<T> operator(.)(const Quaternion<T>& q) const;

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

etc etc...

Aspidus
 
R

Rolf Magnus

Aspidus said:
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<T> operator(*)(const Quaternion<T>& q) const;

Quaternion<T> operator*(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<T> operator(.)(const Quaternion<T>& q) const;

Not possible.
 
T

terminator

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.



Quaternion<T> operator*(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).


Not possible.

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

Aspidus

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,263
Messages
2,571,062
Members
48,769
Latest member
Clifft

Latest Threads

Top