[問題] include 新的cpp debug 會出現問題

看板C_and_CPP作者 (圈圈)時間10年前 (2016/01/28 15:47), 編輯推噓1(1013)
留言14則, 4人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) VS2013 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) opencv 問題(Question): 新建的cpp 要正確debug 都要重建專案 否則會顯示之前dubug的結果 下面範例 第一次debug 會正確 顯示 Test1 Test1 但若把a.cpp b.cpp cout 都改 Test2 在debug 會顯示 Test2 Test 1 而不是 Test2 Test2 唯有重建後才會都正確顯示 ? 但我不太懂這問題 後來我有測試接下來建的cpp 都會這樣 但不知道哪裡出問題? *[36m餵入的資料(Input):*[m *[36m預期的正確結果(Expected Output):*[m *[36m錯誤結果(Wrong Output):*[m *[36m程式碼(Code):(請善用置底文網頁, 記得排版) *[m main.cpp #include "global.h" #include "a.cpp" #include "b.cpp" int main() { a ob1; b ob2; a.init(); b.init(); return 0 ; } a.cpp #include "global.h" class a { private : Mat img; int height, width; public: void init( ) { cout << "Test1" << endl; } }; b.cpp #include "global.h" class b { private : Mat img; int height, width; public: void init() { cout << "Test1" << endl; } }; 補充說明(Supplement): -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.113.193.236 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1453967276.A.189.html

01/28 16:02, , 1F
請問你的global.h裡面有甚麼?
01/28 16:02, 1F

01/28 17:04, , 2F
你為什麼要 include a.cpp b.cpp?
01/28 17:04, 2F

01/28 17:05, , 3F
共同的 class 定義應該要寫在 .h 裡
01/28 17:05, 3F

01/28 17:41, , 4F
global include共同需要的,using space #define
01/28 17:41, 4F

01/28 17:41, , 5F
有用#ifndef_GLOBAL_H_
01/28 17:41, 5F

01/28 17:43, , 6F
不同class處理不同事情,所以寫在不同cpp,不懂寫在.h差別
01/28 17:43, 6F

01/28 18:08, , 7F
宣告和定義分開
01/28 18:08, 7F

01/28 19:09, , 8F
什麼意思 差別是 ?
01/28 19:09, 8F

01/28 19:50, , 9F
這篇文章看一下 google很好用的 http://goo.gl/uTNzKX
01/28 19:50, 9F

01/28 21:31, , 10F
先謝謝 不過我不是編譯錯誤 我是好像編譯連結出現問題
01/28 21:31, 10F

01/28 21:32, , 11F
另外我書上介紹 同個函數 要使用 則命名.h 不然彼此獨立
01/28 21:32, 11F

01/28 21:32, , 12F
通常都命名.cpp
01/28 21:32, 12F

01/28 21:34, , 13F
另外global include define我習慣寫在同一個.h 這樣是不
01/28 21:34, 13F

01/28 21:34, , 14F
好嗎?
01/28 21:34, 14F
文章代碼(AID): #1MgSUi69 (C_and_CPP)