作者ric2k1 (Ric)
看板EE_DSnP
标题[情报] make test 的 error
时间Thu Nov 4 23:19:35 2010
连续两天有同学遇到这样的 compile error 来问我,
我想一定还会有人遇到,就统一在这里回答。
================================================
> compiling: test.cpp
In file included from test.cpp:10:
../../include/calcModNum.h: In static member function ‘static bool
ModNum::ge\
tStrVal(const std::string&, ModNum&)’:
../../include/calcModNum.h:101: error: ‘isValidVarName’ was not declared in
\
this scope
../../include/calcModNum.h:103: error: ‘myStr2Int’ was not declared in this
\
scope
make[1]: *** [test.o] Error 1
make: *** [testmain] Error 2
================================================
两个人造成的原因一样,就是在 calcModNum.h 里头呼叫了 "isValidVarName()" 以及
"myStr2Int()" 两个 functions.
因为这两个 functions 是定义在 myString.cpp 里头的,
如果你在 calcModNum.h 没有宣告这两个 function 的 prototypes,
compiler 就不会知道他们是甚麽东西。
解决的方式:
1. 在 calcModNum.h 里头 #include "util.h"
但这样并不好,我不太鼓励在 .h 里头随便 include 其他的 .h 档
2. 加上:
extern int myStrNCmp(const string& s1, const string& s2, unsigned n);
extern bool myStr2Int(const string& str, int& num);
勉强可以接受,因为我也不太喜欢在 .h 里头看到太多 extern 甚麽的...
(个人观感啦)
3. 将使用这两个 functions 的 member function(s) 定义到 calcModNum.cpp
推荐,这样比较乾净。
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 123.193.11.13