我是C ++新手,我可能会犯一些C ++新手的错误, 因为我是新手,我不知道这个错误会是什么意思是。 我正在使用DevCpp来编译它。线索欢迎。 Ed。You''re my only hope!OK, I gots a mystery on my hands. I''m hoping someone can tell me justwhat the **** is going on here.I''m familiar with other object oriented programming tools, such as Java& REBOL. In an effort to become more familiar with C++, I decided towrite an object oriented BlackJack program. After writing some staticroutines for Faces and Suits, I turned my attention to creating Cardsand Hands. Cards were no problem, Hands are starting to tick me off. :)First, my header file for Hands:================================================== ====================#ifndef _Hand_H_#define _Hand_H_#include "Card.h"class Hand {public:Hand();bool add(Card prmCard);bool canDouble();bool canSplit();int getSize();int getValue();bool isBlackjack();bool isBusted();bool isSoft();void setHidden(int prmHideNo);string toString();string toString(bool prmLong);private:bool clsSoft;int clsCount;int clsHidden;Card clsCards[0];}#endif //_Hand_H_================================================== ====================Next, my C++ file for Hands:================================================== ====================#include <cstdlib>#include <iostream>#include <string>using namespace std;// Declarations...#include "Hand.h"// Definitions...int clsCount;int clsHidden;bool clsSoft;Card clsCards[0];// Constructors...Hand::Hand( ) {}// Methods....... All methods are currently stubs.================================================== ====================Please notice the "definitions" section. When compiled, it produces thefollowing error: "extraneous `int'' ignored."When I remove all definitions in that section, I get:----------------------------------------------------------------------12 Hand.cpp new types may not be defined in a return type12 Hand.cpp return type specification for constructor invalid----------------------------------------------------------------------But when I change the definition section to remove the first, and onlyfirst, int declaration, so that it looks like this:================================================== ====================// Definitions...clsCount;int clsHidden;bool clsSoft;Card clsCards[0];================================================== ====================It compiles successfully!AND! More entertainingly! If I switch the declarations around so thatthe bool is first, like this:================================================== ====================// Definitions...bool clsSoft;int clsCount;int clsHidden;Card clsCards[0];================================================== ====================I get the error: "''bool'' is now a keyword." But, once again, like int,leaving the bool keyword out compiles successfully.What''s going on?I''m a C++ newbie, and I''m probably making some kinda C++ newbie mistake,but because I a newbie, I''ve got no idea what that mistake might be.I''m using DevCpp to compile this. Clues welcome.Ed.推荐答案 Ed Dana写道:Ed Dana wrote: 你是我唯一的希望! 好​​吧,我手上有一个谜。我希望有人可以告诉我 ****这里发生了什么。You''re my only hope!OK, I gots a mystery on my hands. I''m hoping someone can tell me justwhat the **** is going on here. 发布不完整的代码并不是'为了你的事业,你应该将问题提炼成可以编译并展示你问题的东西。 但是......Posting incomplete code doesn''t help your cause, you should distil theproblem down to something that can compile and exhibits your problem.But... > //定义...... int clsCount; int clsHidden; bool clsSoft; 卡片clsCards [0];>// Definitions... int clsCount; int clsHidden; bool clsSoft; Card clsCards[0]; 这些是什么情况?他们似乎复制了你的班级成员。 - Ian Collins。In what context are these? They appear to duplicate your class members.--Ian Collins. [由于某些原因,谷歌回复命令没有正确引用,所以 我必须编辑我想要突出显示的位置,但是 希望我引用的内容与你实际发布的内容相同 张贴...] 1月28日,21:21 ,Ed Dana< EDan ... @ Cox.netwrote:[For some reason the google reply command isn''t quoting correctly, soI''m having to edit in exactly the spot I am trying to highlight, buthopefully what I quote will be the same as what you actuallyposted...]On 28 Jan, 21:21, Ed Dana <[email protected]: 你是我唯一的希望! 好吧,我手上有一个谜。我希望有人可以告诉我 ****这里发生了什么。 我熟悉其他面向对象编程工具,如Java & REBOL。为了更熟悉C ++,我决定用编写一个面向对象的BlackJack程序。在为Faces and Suits编写一些静态的&b $ b例程之后,我将注意力转向创建卡片 和Hands。卡片没问题,手开始勾选我。 :) 首先,我的手头文件: ==================== ============================== ==================== #ifndef _Hand_H_ #define _Hand_H_ #include" Card.h" class Hand { public: Hand(); bool add(Card prmCard); bool canDouble(); bool canSplit(); int getSize(); int getValue(); bool isBlackjack(); bool isBusted(); bool isSoft(); void setHidden( int prmHideNo); string toString(); string toString(bool prmLong); private: bool clsSoft; int clsCount; int clsHidden; 卡片clsCards [0]; }You''re my only hope!OK, I gots a mystery on my hands. I''m hoping someone can tell me justwhat the **** is going on here.I''m familiar with other object oriented programming tools, such as Java& REBOL. In an effort to become more familiar with C++, I decided towrite an object oriented BlackJack program. After writing some staticroutines for Faces and Suits, I turned my attention to creating Cardsand Hands. Cards were no problem, Hands are starting to tick me off. :)First, my header file for Hands:================================================== ====================#ifndef _Hand_H_#define _Hand_H_#include "Card.h"class Hand { public: Hand(); bool add(Card prmCard); bool canDouble(); bool canSplit(); int getSize(); int getValue(); bool isBlackjack(); bool isBusted(); bool isSoft(); void setHidden(int prmHideNo); string toString(); string toString(bool prmLong); private: bool clsSoft; int clsCount; int clsHidden; Card clsCards[0];} 这是你真正的问题。你需要一个分号,而且你没有把b $ b放进去。Here''s your real problem. You need a semi-colon here, and you haven''tput one in. #endif // _ Hand_H_ ============================================= ===== ==================== 接下来,我手中的C ++文件: =============================================== === ==================== #include< cstdlib> #include< iostream> ; #include< string> using namespace std; //声明...... #include" Hand.h"#endif //_Hand_H_================================================== ====================Next, my C++ file for Hands:================================================== ====================#include <cstdlib>#include <iostream>#include <string>using namespace std;// Declarations...#include "Hand.h" 因此,当编译器到达此处时,它希望您将名称 命名为Hand。它认为你在宣布。因此有趣的 结果。So when the compiler gets here, it is expecting you to give the namethe the "Hand" that it thinks you are declaring. Hence the funnyresults. //定义...... int clsCount; int clsHidden; bool clsSoft; Card clsCards [0];// Definitions... int clsCount; int clsHidden; bool clsSoft; Card clsCards[0]; Ed Dana schrieb:Ed Dana schrieb: 你是我唯一的希望! 好​​吧,我手上有一个谜。我希望有人可以告诉我 ****这里发生了什么。You''re my only hope!OK, I gots a mystery on my hands. I''m hoping someone can tell me justwhat the **** is going on here. [...][...] 首先,我的手头文件: =============================================== === ==================== #ifndef _Hand_H_ #define _Hand_H_ #include" Card.h" class Hand {First, my header file for Hands:================================================== ====================#ifndef _Hand_H_#define _Hand_H_#include "Card.h"class Hand { [... ][...] Card clsCards [0]; Card clsCards[0]; 数组不能为零。你想要一个动态阵列吗?然后使用 std :: vector。An array can''t be zero sized. Do you want a dynamic array? Then usestd::vector. }} 分号?Semicolon? #endif // _ Hand_H_ ===================== ============================= ==================== 接下来,我手中的C ++文件: ======================= =========================== ====================#endif //_Hand_H_================================================== ====================Next, my C++ file for Hands:================================================== ==================== [...][...] //声明...... #include Hand.h //定义...... int clsCount; int clsHidden; bool clsSoft; 卡片clsCards [0];// Declarations...#include "Hand.h"// Definitions... int clsCount; int clsHidden; bool clsSoft; Card clsCards[0]; 这些是为了什么? 除非它们是静态的,否则你不必定义类成员变量。 br /> 然后,你必须为它们添加类名称,如下所示: int Hand :: clsCount; 但它们不是静止的...... [...描述一些错误...]What are these for?You don''t have to define class member variables unless they are static.Then, you have to prefix them with the class name like so:int Hand::clsCount;But they aren''t static...[...description of some errors...] 发生了什么事?What''s going on? 类定义之后缺少的分号。 - Thomas http://www.netmeister.org/news/learn2quote.html 这篇关于帮助我,Obi C Kenobi ......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-19 15:29