[問題] include
遇到兩個.h檔必須要互相include對方時發生的問題
//a.h
#ifndef A_H
#define A_H
#include "b.h"
class A
{
A(){_b = new B(this);}
void print(){}
private:
B* _b;
};
#endif
---------------------
//b.h
#ifndef B_H
#define B_H
#include "a.h"
class A;
class B
{
public:
B(A* ptr){
_a = ptr;
_a->print();
}
private:
A* _a;
}
;
#endif
---------------------
compile error:
invalid use of undefined type struct A;
forward declaration of 'struct A'
我是不知道該怎樣做啦請賜教,謝謝。
compiler: devC++ 4.9.9.2
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.136.79.51
※ 編輯: rockwalking 來自: 220.136.79.51 (06/19 01:16)
推
06/19 01:18, , 1F
06/19 01:18, 1F
推
06/19 01:19, , 2F
06/19 01:19, 2F
※ 編輯: rockwalking 來自: 220.136.79.51 (06/19 01:21)
→
06/19 01:22, , 3F
06/19 01:22, 3F
→
06/19 01:24, , 4F
06/19 01:24, 4F
→
06/19 17:39, , 5F
06/19 17:39, 5F
→
06/19 17:40, , 6F
06/19 17:40, 6F
討論串 (同標題文章)
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章