[問題] 出現 was not declared in this scope
開發平台(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 ,
這樣有何差別呢 ??
謝謝 ! !
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 118.163.48.108
→
09/28 14:40, , 1F
09/28 14:40, 1F
→
09/28 15:13, , 2F
09/28 15:13, 2F
→
09/28 15:14, , 3F
09/28 15:14, 3F
推
09/28 15:33, , 4F
09/28 15:33, 4F
→
09/28 15:35, , 5F
09/28 15:35, 5F
推
09/28 15:40, , 6F
09/28 15:40, 6F
→
09/28 15:41, , 7F
09/28 15:41, 7F
→
09/28 15:41, , 8F
09/28 15:41, 8F
→
09/28 16:34, , 9F
09/28 16:34, 9F
推
09/28 18:23, , 10F
09/28 18:23, 10F
→
09/28 18:23, , 11F
09/28 18:23, 11F
→
09/28 20:58, , 12F
09/28 20:58, 12F
→
09/28 20:59, , 13F
09/28 20:59, 13F
→
09/28 20:59, , 14F
09/28 20:59, 14F
→
09/28 21:00, , 15F
09/28 21:00, 15F
→
09/28 21:00, , 16F
09/28 21:00, 16F
→
09/28 21:02, , 17F
09/28 21:02, 17F
→
09/28 21:13, , 18F
09/28 21:13, 18F
→
09/28 21:48, , 19F
09/28 21:48, 19F
→
09/28 22:27, , 20F
09/28 22:27, 20F
→
09/28 23:06, , 21F
09/28 23:06, 21F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 2 篇):