帮助我,Obi C Kenobi ...... [英] Help me, Obi C Kenobi...

查看:71
本文介绍了帮助我,Obi C Kenobi ......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你是我唯一的希望!


好​​吧,我手上有一个谜。我希望有人可以告诉我

****这里发生了什么。


我熟悉其他面向对象编程工具,如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];

}

#endif // _ Hand_H_

=========================== ======================= ====================

接下来,我手中的C ++文件:

==================== ============================== ====================

#include< cstdlib>

#include< iostream>

#include< string>

using namespace std;


//声明......

#include" Hand.h"


//定义......

int clsCount;

int clsHidden;

bool clsSoft;

卡片clsCards [ 0];


//构造函数......

Hand :: Hand(){


}


//方法......

....目前所有方法都是存根。

======= =========================================== ======= =============


请注意定义部分。编译时,它会产生

以下错误:extraneous`int''被忽略。


当我删除该部分中的所有定义时,我得到:

---------------------------------------- ------------------------------

12 Hand.cpp新类型可能未在a中定义返回类型

12 Hand.cpp返回类型规范构造函数无效

---------------------- ------------------------------------------------ <无线电通信/>

但是当我更改定义部分以删除第一个,并且只有

first,int声明时,它看起来像这样:

================================================ == ====================

//定义......

clsCount;

int clsHidden;

bool clsSoft;

卡片clsCards [0];

========== ======================================== ========== ==========


编译成功!


AND!更有趣!如果我切换声明,那么

bool是第一个,就像这样:

================== ================================ ================== ==

//定义......

bool clsSoft;

int clsCount;

int clsHidden;

卡片clsCards [0];

============================= ===================== ====================


我收到错误:"'''bool''现在是关键字。但是,再一次,像int,

离开bool关键字成功编译。


发生了什么事?

我是C ++新手,我可能会犯一些C ++新手的错误,

因为我是新手,我不知道这个错误会是什么意思是。


我正在使用DevCpp来编译它。线索欢迎。


Ed。

You''re my only hope!

OK, I gots a mystery on my hands. I''m hoping someone can tell me just
what 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 to
write an object oriented BlackJack program. After writing some static
routines for Faces and Suits, I turned my attention to creating Cards
and 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 the
following 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 type
12 Hand.cpp return type specification for constructor invalid
----------------------------------------------------------------------

But when I change the definition section to remove the first, and only
first, 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 that
the 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 just
what the **** is going on here.



发布不完整的代码并不是'为了你的事业,你应该将问题提炼成可以编译并展示你问题的东西。

但是......

Posting incomplete code doesn''t help your cause, you should distil the
problem 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, so
I''m having to edit in exactly the spot I am trying to highlight, but
hopefully what I quote will be the same as what you actually
posted...]

On 28 Jan, 21:21, Ed Dana <EDan...@Cox.netwrote:

你是我唯一的希望!


好吧,我手上有一个谜。我希望有人可以告诉我

****这里发生了什么。


我熟悉其他面向对象编程工具,如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 just
what 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 to
write an object oriented BlackJack program. After writing some static
routines for Faces and Suits, I turned my attention to creating Cards
and 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''t
put 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 name
the the "Hand" that it thinks you are declaring. Hence the funny
results.


//定义......

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 just
what 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 use
std::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 ......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆