I don't understand the compilation error C2676
for the below code
#ifndef __VEC_3D_H__
#define __VEC_3D_H__
#include <vector>
#include <cmath>
namespace Internal
{
/** very simple 3D vector/ point */
class Vec3D
{
public:
float mX;
float mY;
float mZ;
/// null constructor
Vec3D(void) {}
/// construct from data
Vec3D(float x, float y, float z) : mX(x), mY(y), mZ(z) {}
inline friend std::ostream& operator<< (std::ostream& os, const Vec3D& v)
{
os << "(" << v.mX << ", " << v.mY << ", " << v.mZ << ")";
return os;
}
};
}
#endif
I have put a functionally identical code in another class and it compiles and runs fine. What is wrong here?
EDIT1: corrected BOBVec3d to Vec3D, was a typo
EDIT2: removed using namespace Internal;
, it is indeed point-defeating to have it in a header file
missing #include <iostream>
at the top.
Fixed it. (Oh what terribly terribly poor compilation errors in C++ can be..)
I had this error
Error C2676 binary '<<': 'std::ofstream' does not define this operator or a conversion to a type acceptable to the predefined operator Project2c++ c:\users\dinga\desktop\practice projects for c++\project2c++\project2c++\fruit.h
As a solution
i just used #include <fstream> (ie fstream)
in the header file where the class was defined.
this worked for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With