質問編集履歴

2

誤字修正

2018/12/12 02:51

投稿

torimingo
torimingo

スコア122

test CHANGED
File without changes
test CHANGED
@@ -8,77 +8,107 @@
8
8
 
9
9
  ━━━━━ Actualクラス ━━━━━
10
10
 
11
- 1 #include "callback.h"
11
+ 1 #ifndef ACTUAL
12
12
 
13
- 2
13
+ 2 #define ACTUAL
14
14
 
15
- 3 class Callback;
15
+ 3
16
16
 
17
- 4 class Actual {
17
+ 4 #include "callback.h"
18
18
 
19
- 5 public:
19
+ 5
20
20
 
21
- 6 int get() {
21
+ 6 class Callback;
22
22
 
23
- 7 return 3;
23
+ 7 class Actual {
24
24
 
25
- 8 }
25
+ 8 public:
26
26
 
27
- 9 Callback *callback;
27
+ 9 int get() {
28
28
 
29
+ 10 return 3;
30
+
31
+ 11 }
32
+
33
+ 12 Callback *callback;
34
+
29
- 10 };
35
+ 13 };
36
+
37
+ 14
38
+
39
+ 15 #endif
30
40
 
31
41
 
32
42
 
33
43
  ━━━━━ Callbackクラス ━━━━━
34
44
 
35
- 1 #include "logic.h"
45
+ 1 #ifndef CALLBACK
36
46
 
37
- 2
47
+ 2 #define CALLBACK
38
48
 
39
- 3 class Logic;
49
+ 3
40
50
 
41
- 4 class Callback {
51
+ 4 #include "logic.h"
42
52
 
43
- 5 public:
53
+ 5
44
54
 
45
- 6 void func() {
55
+ 6 class Logic;
46
56
 
47
- 7 logic->print();
57
+ 7 class Callback {
48
58
 
49
- 8 }
59
+ 8 public:
50
60
 
51
- 9 Logic *logic;
61
+ 9 void func() {
52
62
 
63
+ 10 logic->print();
64
+
65
+ 11 }
66
+
67
+ 12 Logic *logic;
68
+
53
- 10 };
69
+ 13 };
70
+
71
+ 14
72
+
73
+ 15 #endif
54
74
 
55
75
 
56
76
 
57
77
  ━━━━━ Logicクラス ━━━━━
58
78
 
59
- 1 #include <iostream>
79
+ 1 #ifndef LOGIC
60
80
 
61
- 2 #include "actual.h"
81
+ 2 #define LOGIC
62
82
 
63
- 3 using namespace std;
83
+ 3
64
84
 
65
- 4
85
+ 4 #include <iostream>
66
86
 
67
- 5 class Actual;
87
+ 5 #include "actual.h"
68
88
 
69
- 6 class Logic {
89
+ 6 using namespace std;
70
90
 
71
- 7 public:
91
+ 7
72
92
 
73
- 8 void print() {
93
+ 8 class Actual;
74
94
 
75
- 9 cout << actual->get() << endl;
95
+ 9 class Logic {
76
96
 
77
- 10 }
97
+ 10 public:
78
98
 
79
- 11 Actual *actual;
99
+ 11 void print() {
80
100
 
101
+ 12 cout << actual->get() << endl;
102
+
103
+ 13 }
104
+
105
+ 14 Actual *actual;
106
+
81
- 12 };
107
+ 15 };
108
+
109
+ 16
110
+
111
+ 17 #endif
82
112
 
83
113
 
84
114
 

1

エラー出力を追記しました

2018/12/12 02:51

投稿

torimingo
torimingo

スコア122

test CHANGED
File without changes
test CHANGED
@@ -18,7 +18,7 @@
18
18
 
19
19
  5 public:
20
20
 
21
- 6 void get() {
21
+ 6 int get() {
22
22
 
23
23
  7 return 3;
24
24
 
@@ -94,7 +94,7 @@
94
94
 
95
95
  5 int main() {
96
96
 
97
- 6 Actaul actual;
97
+ 6 Actual actual;
98
98
 
99
99
  7 Callback callback;
100
100
 
@@ -118,4 +118,32 @@
118
118
 
119
119
  ```
120
120
 
121
+
122
+
123
+ エラー出力を以下に示します。
124
+
125
+ ```
126
+
127
+ In file included from callback.h:4:0,
128
+
129
+ from actual.h:4,
130
+
131
+ from main.cpp:1:
132
+
133
+ logic.h: In member function ‘void Logic::print()’:
134
+
135
+ logic.h:12:17: error: invalid use of incomplete type ‘class Actual’
136
+
137
+ cout << actual->get() << endl;
138
+
139
+ ^~
140
+
141
+ logic.h:8:7: note: forward declaration of ‘class Actual’
142
+
143
+ class Actual;
144
+
145
+ ```
146
+
147
+
148
+
121
149
  解消方法をご存知の方がおりましたら、教えて頂けると幸いです。