Re: [問題] 出現 was not declared in this scope
※ 引述《maik060 (^.< 啾咪 ~)》之銘言:
: 開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
: linux
: 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
: no
: 問題(Question):
: 有一個檔案 c.cpp 的內容如下,
: #include "./externC.h"
: int main(int argc, const char *argv[])
: {
: foo();
: return 0;
: }
: 這是 externC.h 的內容,
: void foo(void);
: 使用 gcc -c c.cpp 卻出現了,
: c.cpp: In function ‘int main(int, const char**)’:
: c.cpp:4:9: error: ‘foo’ was not declared in this scope
: 若是將 c.cpp 改成如下
: void foo(void);
: int main(int argc, const char *argv[])
: {
: foo();
: return 0;
: }
: 就沒問題了,
: 請問這將 void foo(void); 寫在 .cpp 中,
: 跟將 void foo(void); 寫在 .h 中,在讓 c.cpp 做 include ,
: 這樣有何差別呢 ??
: 謝謝 ! !
這是三個檔案
==c.c==
#include "./externC.h"
int main(int argc, const char *argv[])
{
foo();
return 0;
}
==c.cpp==
#include "./externC.h"
int main(int argc, const char *argv[])
{
foo();
return 0;
}
==externC.h==
void foo(void);
然後分別下
gcc -c c.c (沒有問題)
gcc -c c.cpp 出現下面的 error message
c.cpp: In function ‘int main(int, const char**)’
c.cpp:4:9: error: ‘foo’ was not declared in this scope
還是不知道為什麼 .. 感謝 ! !
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 118.163.48.108
→
09/28 22:31, , 1F
09/28 22:31, 1F
→
09/28 22:33, , 2F
09/28 22:33, 2F
→
09/28 22:33, , 3F
09/28 22:33, 3F
→
09/28 22:34, , 4F
09/28 22:34, 4F
→
09/28 22:34, , 5F
09/28 22:34, 5F
→
09/28 22:36, , 6F
09/28 22:36, 6F
→
09/28 22:37, , 7F
09/28 22:37, 7F
→
09/28 22:38, , 8F
09/28 22:38, 8F
→
09/28 22:38, , 9F
09/28 22:38, 9F
→
09/28 22:39, , 10F
09/28 22:39, 10F
→
09/28 22:40, , 11F
09/28 22:40, 11F
→
09/28 22:41, , 12F
09/28 22:41, 12F
→
09/28 22:41, , 13F
09/28 22:41, 13F
→
09/28 22:41, , 14F
09/28 22:41, 14F
→
09/28 22:42, , 15F
09/28 22:42, 15F
→
09/28 22:46, , 16F
09/28 22:46, 16F
→
09/28 22:49, , 17F
09/28 22:49, 17F
→
09/28 22:50, , 18F
09/28 22:50, 18F
→
09/28 22:56, , 19F
09/28 22:56, 19F
→
09/28 23:01, , 20F
09/28 23:01, 20F
→
09/28 23:01, , 21F
09/28 23:01, 21F
→
09/28 23:02, , 22F
09/28 23:02, 22F
→
09/28 23:03, , 23F
09/28 23:03, 23F
→
09/28 23:03, , 24F
09/28 23:03, 24F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):