iosfwdを含めると、標準文字列を含む出力ストリームが機能しなくなる理由を理解しようとしています。
// hc_list.h file
#ifndef HC_LIST_H
#define HC_LIST_H
#include <cstdlib>
#include <iosfwd> // including this file makes the output operator throw errors
#include <list>
template <typename T>
class hcList
{
private:
std::list<T> selfList ; // a single internal STL list to hold the values
public:
hcList(void) {} ;
~hcList(void){} ;
template <typename U> friend std::ostream& operator<<(std::ostream &, const hcList<U> &) ;
} ;
template <typename U>
std::ostream& operator<<(std::ostream &out, const hcList<U> &outList)
{
out << "test" << std::endl ; // this line throws two errors, stated below
return out ;
}
#endif // HC_LIST_H
このコードはmain.cppファイルに含まれており、main関数は次のとおりです。
// main.cpp file
#include <iostream>
#include "hc_list.h"
int main()
{
std::cout << "Begin Test" << std::endl;
return 0;
}
このコードを実際に利用してエラーを生成するには、リストヘッダーファイルを含む空のcppファイルが必要です。
// anyNamedFile.cpp file
#include "hc_list.h"
コンパイルしようとすると、次のエラーが発生します。
error: no match for 'operator<<' in 'out<< "test"'
error: 'endl' is not a part of 'std'
std名前空間が台無しになり、文字列を出力できなくなった原因は何ですか?