#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)
{
os<<"Hello World!";
return os;
}
자료형에 상관없이 <<연산자 오버로딩 할려고 했는데
이런식으로 만들면 링킹에러뜸
아마 컴파일러가 함수 템플릿이라고 인식해서 에러 뜨는것같은데
friend ostream& operator<<(ostream& os, const AAA<int>& ref);
friend ostream& operator<<(ostream& os, const AAA<char>& ref);
이런식으로 일일이 선언해주는거 말고 자료형에 상관없이 할수있는 방법이 있나?
'C++ > 공개글' 카테고리의 다른 글
리틀 에디안과 빅 에디안의 차이점 (0) | 2013.01.26 |
---|---|
함수 템플릿에서 궁금한 거. (0) | 2013.01.26 |
멤버함수의 선언과 정의 분리 시 참고사항 (0) | 2013.01.26 |
static binding과 dynamic binding (0) | 2013.01.26 |
Polymorphism의 조건 (0) | 2013.01.26 |