Hi,
I have this following method, wanting to add a string to a std stream
the function toString() returns a pointer to a string. the question is, when I add it to a stream, does it create a copy or add the current pointer, and therefore, what is the correct time to release the allocated memory of this pointer?
I just don't get this whole streaming thing...
Code://Edge.h class Edge { char* toString() const; }; #endif //EdgeNode.h class EdgeNode { friend std::ostream& operator << (ostream& out,const EdgeNode &eNode); }; //EdgeNode.cpp #include EdgeNode.h ostream& operator << (ostream &out, const EdgeNode &eNode) { char *p=eNode.m_edge.toString(); return out << p; delete [] p; } //EdgeList.h class EdgeList { friend std::ostream& operator << (ostream& out,EdgeList eList &); }