#include <iostream>
#include <sstream>
class A
{
public:
A();
~A();
inline A(float _x, float _y, float _z) :
x(_x), y(_y), z(_z)
{
}
inline void Set(float _x, float _y, float _z);
float x, y, z;
friend std::ostream& operator<<(std::ostream& out, const A& source);
friend std::wostringstream& operator<<(std::wostringstream& out, const A& source);
private:
};
class B
{
public:
A* ArrayOfA;
bool Initialize(const A* samples,
unsigned int count);
friend std::wostringstream& operator<<(std::wostringstream& out, const B& source);
B();
~B();
private:
};
B::B()
{
}
B::~B()
{
}
bool B::Initialize(const A* samples,
unsigned int count)
{
ArrayOfA = new A[count];
// copy data
for (unsigned int i = 0; i < count; ++i)
{
ArrayOfA[i] = samples[i];
}
return true;
}
inline void
A::Set(float _x, float _y, float _z)
{
x = _x; y = _y; z = _z;
}
A::A()
{
}
A::~A()
{
}
std::ostream&
operator<<(std::ostream& out, const A& source)
{
out << '<' << source.x << ',' << source.y << ',' << source.z << '>';
return out;
}
std::wostringstream&
operator<<(std::wostringstream& out, const A& source)
{
out << '<' << source.x << ',' << source.y << ',' << source.z << '>';
return out;
}
std::wostringstream&
operator<<(std::wostringstream& out, const B& source)
{
for (unsigned int i = 0; i < 4; ++i)
{
out << ":" << source.ArrayOfA[i] << std::endl;
//ERROR:E0349 no operator "<<" matches these operands
//ERROR:C2679 binary '<<' : no operator found which takes a right-hand operand of type'A' (or there is no acceptable conversion)
}
return out;
return out;
}
int main()
{
A a = A(1, 2, 3);
std::cout << "a output:" <<a << std::endl;
std::wostringstream wss;
wss << a;
std::wcout << "a output by wss:" << wss.str() << std::endl;
A sampleA[4];
sampleA[0].Set(-6.0f, 3.0f, 0.0f);
sampleA[1].Set(0.0f, 0.0f, 0.0f);
sampleA[2].Set(-3.0f, -3.0f, 0.0f);
sampleA[3].Set(6.0f, 0.0f, 0.0f);
B b;
b.Initialize(sampleA, 4);
system("pause");
return 0;
}