[問題] 專案裡不同.cpp檔間的struct引用

看板C_and_CPP (C/C++)作者 (遊戲boy)時間10年前 (2015/10/01 20:40), 10年前編輯推噓3(301)
留言4則, 3人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) VC++ 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) OpenCV 問題(Question): 如何在A.cpp引用B.cpp中的struct? 餵入的資料(Input): 所說的struct: typedef struct blob_{ int a CvScalar brgb; }blob; typedef struct slicrtn_{ vector<blob> fnlblob; vector<Mat> roimgs; }slicrtn; 預期的正確結果(Expected Output): (slicrtn原本是B.h中的結構,欲在A中引用此結構) 將B.cpp output的slicrtn結構的物件 成功當成A.cpp中函式的input並編譯執行 錯誤結果(Wrong Output): 目前我是兩個.h檔中都typedef這個struct = = 想當然爾結果錯誤就是 'blob_' : 'struct' 類型重複定義 'slicrtn_' : 'struct' 類型重複定義 我兩個.h檔頭尾都有用#ifndef#define#endif夾住 想問一下這個情況該如何解決? 程式碼(Code):(請善用置底文網頁, 記得排版) 專題中的Main: Slic slic; // Slic是B.cpp中的類別 slicrtn fnlrslt = slic.bb(); // bb是B.cpp中的函式 aa(fnlrslt); // aa是A.cpp中的函式 補充說明(Supplement): 拜託各位大大指點迷津了!! 感謝!! -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.118.235.69 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1443703255.A.6D4.html

10/01 21:22, , 1F
把其中一個刪掉呢?
10/01 21:22, 1F

10/01 21:46, , 2F
A要引用B 所以struct放在B裡面就好 或是抽出共用的放在C
10/01 21:46, 2F

10/01 21:47, , 3F
A B都引用C
10/01 21:47, 3F
只在B.h中宣告,然後A.cpp 中 include B.h的話 A.h中的aa宣告就會出錯了 'slicrtn' : 未宣告的識別項 ※ 編輯: UCboy (140.118.235.69), 10/01/2015 22:19:24 不過在A.h中include B.h就可以了 !! 第一次在.h中引用自己其他的.h檔 -.- 感謝各位!! ※ 編輯: UCboy (140.118.235.69), 10/01/2015 22:29:13

10/02 01:38, , 4F
extern?
10/02 01:38, 4F
文章代碼(AID): #1M3IdNRK (C_and_CPP)
文章代碼(AID): #1M3IdNRK (C_and_CPP)