查看: 1291|回复: 9
|
C++高手这奇怪的问题。。。
[复制链接]
|
|
偶正在开发一支算命程序,下面是简化後的结果
#include <string>
using namespace std;
class Kua {
public :
Kua(int sh, int yy) { shape = sh; yao = yy; }
Kua() { shape = 0; yao = 0; }
void SettingKua(int sh, int yy) { shape = sh; yao = yy; }
int GetShape() { return(shape); }
int GetYao() { return(yao);
string GetKuaName() { return( KuaName[shape] + YaoName[yao] ); };
private :
static string KuaName[];
static string YaoName[];
int shape;
int yao;
};
/*class Kua {
public :
Kua(int sh, int yy) { shape = sh; yao = yy; }
Kua() { shape = 0; yao = 0; }
void SettingKua(int sh, int yy) { shape = sh; yao = yy; }
int GetShape() { return(shape); }
int GetYao() { return(yao); }
string GetKuaName() { return( KuaName[shape] + YaoName[yao] ); };
private :
static string KuaName[];
static string YaoName[];
int shape;
int yao;
};*/
string Kua::YaoName[] = {"上", "初", "二", "三", "四", "五"};
string Kua::KuaName[] = {"坤", "復", "師", "臨", "謙", "明夷", "升", "泰", "豫", "震", "解",
"歸妹", "小過", "豐", "恒", "大壯", "比", "屯", "坎", "節", "蹇", "既濟", "井", "需",
"萃", "隨", "困", "兌", "咸", "革", "大過", "夬", "剝", "頤", "蒙", "損", "艮", "賁",
"蠱", "大畜", "晉", "噬嗑", "未濟", "睽", "旅", "離", "鼎", "大有", "觀", "益", "渙",
"中孚", "漸", "家人", "巽", "小畜", "否", "無妄", "訟", "履", "遁", "同人", "姤", "乾"};
int main() {}
看起来两个class一模一样,可是如果你用上面的Class宣告,会有一堆的文法错
误,改用下面的Class又没有。。。有谁知道为什么,让大家都可以学点东西啦。
我用gcc 3.4.3, OS是red hat Enterprise Linux 4.0 AS. |
|
|
|
|
|
|
|
发表于 17-5-2007 02:06 PM
|
显示全部楼层
楼主最好要把你 error messages 放上来。。这样比较容易分析 |
|
|
|
|
|
|
|
发表于 17-5-2007 05:26 PM
|
显示全部楼层
class Kua {
public :
Kua(int sh, int yy) { shape = sh; yao = yy; }
Kua() { shape = 0; yao = 0; }
void SettingKua(int sh, int yy) { shape = sh; yao = yy; }
int GetShape() { return(shape); }
-----> int GetYao() { return(yao);
string GetKuaName() { return( KuaName[shape] + YaoName[yao] ); };
private :
static string KuaName[];
static string YaoName[];
int shape;
int yao;
};
/*class Kua {
public :
Kua(int sh, int yy) { shape = sh; yao = yy; }
Kua() { shape = 0; yao = 0; }
void SettingKua(int sh, int yy) { shape = sh; yao = yy; }
-----> int GetShape() { return(shape); }
int GetYao() { return(yao); }
string GetKuaName() { return( KuaName[shape] + YaoName[yao] ); };
private :
static string KuaName[];
static string YaoName[];
int shape;
int yao;
};*/
那里不一样。
[ 本帖最后由 糯米鸡 于 17-5-2007 05:31 PM 编辑 ] |
|
|
|
|
|
|
|

楼主 |
发表于 17-5-2007 06:31 PM
|
显示全部楼层
回复 #3 糯米鸡 的帖子
谢谢指点。偶是第一次用gcc, 以前用VB, 文法有一点小错,顶多不过一两行
error messages, 到了gcc就变十几行酱多。而且第一行错误从
string Kua::YaoName[] = {"上", "初", "二", "三", "四", "五"}; 开始,离真正
出错的地方很远。酱的东西抓bug不是很困难吗?
请问各位大大能不能指点一下,抓bug的技巧 ?
[ 本帖最后由 sktan007 于 17-5-2007 06:44 PM 编辑 ] |
|
|
|
|
|
|
|
发表于 28-5-2007 12:01 AM
|
显示全部楼层
Debugging 需要经验, 就像这个问题, 其实只是一个 } 的问题。
请问你有用任何IDE 来写code 吗?
我相信是没有, 如果有应该会察觉到这个 } 问题。
要简单的, 可以用 Gedit , 要高级点的, 可以找 anjuta, codeblocks 来尝试。 |
|
|
|
|
|
|
|

楼主 |
发表于 28-5-2007 10:04 AM
|
显示全部楼层
回复 #5 jangancari 的帖子
以前只用過VB,在Linux還沒試用IDE, 因為anjuta安裝很多次都失
敗,anyway這套red hat己經兩年了,所以不久前我去Ubuntu申請一套cd(應該有anjuta或codeblock了吧),但是我的cpu 是celeron 2.0,
他們卻寄給我兩張AMD 64bit的版本,請問可以安裝嗎? |
|
|
|
|
|
|
|
发表于 28-5-2007 04:35 PM
|
显示全部楼层
Celeron 2。0 应该是 32 bits 的吧,所以是不能安装的,或许你可以去官方网站下载 32 bits 的
至于editor,我倒建议用VIM,虽然开始比较难上手,但是设定对后真的很好用,可以 hightlight keyword,cindent又会自动 indent code,编译又方便。。最重要的还是免费的。。
设定 vinrc 后,complile 只需安 F5 键就可以了。。
[ 本帖最后由 onlylonly 于 28-5-2007 04:36 PM 编辑 ] |
|
|
|
|
|
|
|

楼主 |
发表于 29-5-2007 07:48 PM
|
显示全部楼层
回复 #7 onlylonly 的帖子
谢谢!我还是想安装一套新版Linux, 然後download NetBean5.5来,主要是看中他有一套现成的IDE, 又方便写gui。NetBean不只
是Java平台,也有提供C++使用。
所以现在又去试试申请一套ubuntu 7.04(上次是6.06), 如果还不
可以就干脆去申请一套Solaris好了。 |
|
|
|
|
|
|
|
发表于 29-5-2007 08:49 PM
|
显示全部楼层
Debugging by Thinking: A Multidisciplinary Approach (HP Technologies)个人认为这是一本很不错的书, 你可以试试参考。 |
|
|
|
|
|
|
|

楼主 |
发表于 29-5-2007 08:55 PM
|
显示全部楼层
回复 #9 糯米鸡 的帖子
谢谢你的好介绍.
请问一下,大大下面那几行文言文(静以修身,俭以...)出自那本古书?中庸?大学?酱深的古书
你都可以看,真佩服!

[ 本帖最后由 sktan007 于 29-5-2007 09:05 PM 编辑 ] |
|
|
|
|
|
|
| |
本周最热论坛帖子
|