-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_01.cpp
More file actions
64 lines (49 loc) · 1.1 KB
/
Copy pathtest_01.cpp
File metadata and controls
64 lines (49 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <HXprint/print.h>
// 前向声明 & 模版名称二阶段查找
#define __test_Forward_Declaration__
#ifdef __test_Forward_Declaration__
template <typename T>
struct A;
struct B {
template <typename T>
auto func(A<T> const& a) {
a.func();
return a.data;
}
template <typename T, typename = std::enable_if_t<!std::is_same_v<T, void>>>
auto func(A<T> const& a) {
// 恒成立, 无所谓, 不会触发的
static_assert(sizeof(T) > 0, "error");
}
};
template <typename T = void>
struct A {
int data;
void func() const {
HX::print::println("A func");
}
};
#else
struct A;
struct B {
auto func(A const& a) {
// Member access into incomplete type 'const A'
// 成员访问不完整类型 "const A"
a.func();
return a.data;
}
};
struct A {
int data;
void func() const {
HX::print::println("A func");
}
};
#endif
int main() {
auto res1 = B{}.func(A{});
static_cast<void>(res1);
// auto res2 = B{}.func(A<int>{});
// static_cast<void>(res2);
return 0;
}