【发布时间】:2016-09-07 23:40:27
【问题描述】:
我到处看到每个人都在几行中重载了
在我的 .h 中,我有:
friend std::ostream& operator<<(std::ostream& os, const Test& test);
在我的 .cpp 我有:
std::ostream& operator<<(std::ostream& out,const DeckOfCards& deck) {
out << "oi"; //just testing with a normal string before i try methods
return out;
}
最后在我的主要功能中:
Test* test = new Test();
std::cout << "output is: " << test << std::endl;
有人可以告诉我我做错了什么吗? 提前致谢。
【问题讨论】:
-
不要不必要地使用new/delete。
标签: c++ output overloading