Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template<typename T>
- class A {
- private:
- int a = 0;
- public:
- void func(A<double> second) {
- cout << second.a;
- }
- };
- void main()
- {
- A<int> first;
- A<double> second;
- first.func(second);
- }
- template<typename T>
- class A {
- private:
- int a = 0;
- public:
- friend void A::func(A<double> second);
- void func(A<double> second) {
- cout << second.a;
- }
- };
- public:
- int a = 0;
- template <typename> friend class A;
- template <typename U> friend void A<U>::func(A<double>);
- template<typename T> class A {
- private:
- int a = 0;
- public:
- void func(A<double>);
- };
- template<> class A<double> {
- private:
- int a = 0;
- public:
- template <typename U> friend void A<U>::func(A<double>);
- void func(A second) {
- cout << second.a;
- }
- };
- template<typename T>
- inline void A<T>::func(A<double> second) {
- cout << second.a;
- }
- #include <iostream>
- template<typename T>
- class node {
- public:
- explicit node(T _value)
- : m_value(_value)
- {}
- public:
- template <typename U>
- void add_child(node<U>& _node) {
- // логика, не относящаяся к примеру
- std::clog << "добавлена дочерняя нода [value=" << _node.m_value << "]n";
- }
- protected:
- T m_value;
- template <typename U>
- friend class node;
- };
- int main() {
- node<int> node_i { 1 };
- node<long> node_l { 2 };
- node<short> node_s { 3 };
- node_i.add_child(node_l);
- node_l.add_child(node_s);
- return 0;
- }
Add Comment
Please, Sign In to add comment