#include<iostream>
using namespace std;
template <typename T>
class AAA
{
private :
T num;
public:
AAA(T _num) : num(_num)
{}
friend ostream& operator<<(ostream& os, const AAA<T>& ref);
};
template <typename T>
ostream& operator<<(ostream& os, const AAA<T>& ref)
{
cout<<"Hello World!"<<endl;
return os;
}
자료형에 상관없이 >>연산자 오버로딩 할려고 했는데
이런식으로 만들면 링킹에러뜸
아마 컴파일러가 함수 템플릿이라고 인식해서 에러 뜨는것같은데
friend ostream& operator<<(ostream& os, const AAA<int>& ref);
friend ostream& operator<<(ostream& os, const AAA<char>& ref);
이런식으로 일일이 선언해주는거 말고 자료형에 상관없이 할수있는 방법 없음?
os 스트림을 반환해야되는데 왜 갑자기 cout으로 출력했지?
함수 본체에 os << \"Hello World!\"<<endl; 이렇게 써야되지 않나?
아 그러네 os로 써야되는데 습관적으로 cout으로 썼네요