Pirority for operators

Hey! I'm new to C++ and I need some help on my coding. I have designed a class of vectors (threevector is the name of the class constructor) and overloaded the + and ^ signs to represent dot product and cross product respectively.

e.g

threevector operator^(threevector v_other)
{
threevector crossporduct=(xcoord * v_other.gety() -.........);

return crossproudct
}

I face a problem. First I need to make sure that when a double is crossproduct with a vector, an error message is displayed on screen (cout) that says that it has to be between 2 vectors. I've tried all means and ways to include it in the () but apparently it only takes in 1 parameter. Putting if into the code also seem to mess it up.

Second, I need to write a code to make sure that when I do v1*v2^v3, it is read as v1*(v2^v3) instead of (v1*v2)^v3. #define? Priority queues? I'm confused.

Thanks so much!
I don't think I get your first question. If you want to keep the user from multiplying a vector by a double, then just don't overload operator* as taking a double.

As for your second question, that's impossible. C++ doesn't allow changing the precedence of even overloaded operators. That's just the way it is and there's no way around it.
Last edited on
Topic archived. No new replies allowed.