public.h
#include<iostream.h>
#ifndef _PUBLIC_H_
#define _PUBLIC_H_
template<class T> class second;
template<class T>
class first
{
public:
first(T tmp);
~first();
template<class T1> void put(second<T1> tmp);
private:
T value;
};
template<class T>
class second
{
public:
second(T tmp);
~second();
private:
T value;
template<class T> friend class first;
};
#endif
public.cpp
#include"public.h"
template<class T> first<T>::first(T tmp)
{
value=tmp;
}
template<class T> first<T>::~first()
{
}
template<class T> template<class T1>
void first<T>::put(second<T1> tmp)
{
cout<<tmp.value<<":"<<value<<endl;
}
template<class T>
second<T>::second(T tmp)
{
value=tmp;
}
template<class T>
second<T>::~second()
{
}
main.cpp
#include"public.h"
#include<iostream.h>
int main()
{
first<int> a(66);
second<int> b(88);
second<char> c('c');
a.put(b);
a.put(c);
return 0;
}
#include<iostream.h>
#ifndef _PUBLIC_H_
#define _PUBLIC_H_
template<class T> class second;
template<class T>
class first
{
public:
first(T tmp);
~first();
template<class T1> void put(second<T1> tmp);
private:
T value;
};
template<class T>
class second
{
public:
second(T tmp);
~second();
private:
T value;
template<class T> friend class first;
};
#endif
public.cpp
#include"public.h"
template<class T> first<T>::first(T tmp)
{
value=tmp;
}
template<class T> first<T>::~first()
{
}
template<class T> template<class T1>
void first<T>::put(second<T1> tmp)
{
cout<<tmp.value<<":"<<value<<endl;
}
template<class T>
second<T>::second(T tmp)
{
value=tmp;
}
template<class T>
second<T>::~second()
{
}
main.cpp
#include"public.h"
#include<iostream.h>
int main()
{
first<int> a(66);
second<int> b(88);
second<char> c('c');
a.put(b);
a.put(c);
return 0;
}