Feb 17, 2019 at 2:42pm UTC
I am trying to make a vector class. Here is a simplified version of my code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
#include <iostream>
#include <cmath>
#include <string>
class VectorThree {
public :
float x,y,z;
void rotateZaxis(const float angle);
friend std::ostream& operator <<(std::ostream& os, const VectorThree& v);
};
void VectorThree::rotateZaxis(const float angle) {
float oldX = this ->x;
float oldY = this ->y;
float angleSin = sin(angle);
float angleCos = cos(angle);
std::cout >> angleSin;
//this->x = newX;
//this->y = newY;
};
std::ostream& operator <<(std::ostream& os, const VectorThree& v) {
os << '<' << v.x << ',' << v.y << ',' << v.z << '>' ;
return os;
};
This throws
error: no match for 'operator>>' (operand types are 'std::ostream' {aka 'std::basic_ostream<char>' } and 'float' )
when I call
rotateZaxis
. What am I doing wrong?
Last edited on Feb 17, 2019 at 2:43pm UTC
Feb 17, 2019 at 2:48pm UTC
"std::cout << angleSin;
" not "std::cout >> angleSin;
cout uses the '<<' insertion operator.
Feb 17, 2019 at 7:12pm UTC
Thanks! I left C++ for a while and am having trouble getting these straight.