C++ Library Extensions
2022.12.09
To help learn modern C++ programming
042-partial_type.cpp
Go to the documentation of this file.
1
#include <iostream>
2
3
template
<
typename
ElementTypeB>
class
TypeB
;
4
5
template
<
typename
ElementTypeA>
6
class
TypeA
7
{
8
template
<
typename
ElementTypeB>
friend
class
TypeB
;
9
10
private
:
11
ElementTypeA m_data{};
12
13
public
:
14
15
template
<
typename
ElementTypeB>
16
void
operation_over_type_b
(
TypeB<ElementTypeB>
b);
17
};
18
19
template
<
typename
ElementTypeB>
20
class
TypeB
21
{
22
template
<
typename
ElementTypeA>
friend
class
TypeA
;
23
24
private
:
25
ElementTypeB m_data{};
26
27
public
:
28
29
template
<
typename
ElementTypeA>
30
void
operation_over_type_a
(
TypeA<ElementTypeA>
a)
31
{
32
std::cout
<< a.m_data <<
std::endl
;
33
}
34
35
};
36
37
template
<
typename
ElementTypeA>
38
template
<
typename
ElementTypeB>
39
void
TypeA<ElementTypeA>::operation_over_type_b
(
TypeB<ElementTypeB>
b)
40
{
41
std::cout
<< b.m_data <<
std::endl
;
42
}
43
44
int
main
()
45
{
46
TypeA<int>
a;
47
48
TypeB<int>
b;
49
50
a.
operation_over_type_b
(b);
51
52
b.
operation_over_type_a
(a);
53
}
main
int main()
Definition:
042-partial_type.cpp:44
cout
auto & cout
Definition:
044-functional.cpp:3
endl
auto & endl
Definition:
apply_operations.cpp:32
TypeA
Definition:
042-partial_type.cpp:7
TypeA::operation_over_type_b
void operation_over_type_b(TypeB< ElementTypeB > b)
Definition:
042-partial_type.cpp:39
TypeB
Definition:
025-template_members.cpp:64
TypeB::operation_over_type_a
void operation_over_type_a(TypeA< ElementTypeA > a)
Definition:
042-partial_type.cpp:30
CppExtension
examples
042-partial_type.cpp
Generated by
1.9.4