#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);


이런식으로 일일이 선언해주는거 말고 자료형에 상관없이 할수있는 방법이 있나?





Posted by huammmm1
,