operator << overload

自古美人都是妖i 提交于 2019-12-06 06:55:21

You have using std::ofstream instead of using std::ostream, so it doesn't know what ostream is.

You also need to include <ostream>.

Really, though, there's no reason to use using anything; you should just qualify the names with the namespace (especially if this is a header file, to avoid polluting the global namespace of other files):

friend std::ostream& operator<< (std::ostream&, const Dog&);

The using keyword just means to let you access something without prefixing it with its namespace. In orther words, using std::ofstream; just says to let you access std::ofstream as ofstream.

You also seem to need a #include <iostream>; that's why the compiler doesn't know what ostream is. Put that in, change the friend declaration to friend std::ostream& operator<< (std::ostream&, const Dog&);, and get rid of all the using stuff, since it's bad form to put using in a header, and you should be okay.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!