在OOP中提供帮助 [英] Help in OOP

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

问题描述

大家好


我不是优秀的OOP程序员,试图在OOP中实现我已经工作的

代码。


我有类似这样的课程。


类Datalogger {

public:

UINT Port;

BOOL bReady;


Datalogger(UINT x,bool y);

~Datalogger();


bool LOpen();

bool LStatus();


};

一切正常,直到 bool LStatus();"


bool LStatus()

{

......这里我有一堆的东西;

但是我在这里遇到问题


Waitforevent(端口,INFINTE,& bReady)

if(bReady)

{

.......

.....一些东西;

.. .......
}

}

其中Waitforevent是我的I / O板驱动程序附带的.I

没有使用此功能。

它给出了

bReady = true对事件的影响。


我的问题是我可以像这样使用成员变量

我的意思是我可以使用成员变量的地址来实现某些功能。 />

Hi guys

I am not good OOP programmer ,trying to implement my already working
code in OOP.

I have somthing like this class.

class Datalogger{
public:
UINT Port;
BOOL bReady ;

Datalogger (UINT x ,bool y);
~Datalogger ();

bool LOpen ();
bool LStatus ();

};
Everything is OK till "bool LStatus ();"

bool LStatus ()
{
...... Here I have bunch of stuff;
but I get problem here

Waitforevent( Port , INFINTE , &bReady)
if(bReady)
{
.......
.....some stuff ;
.......

}
}
Where "Waitforevent" is fucntion came with driver of my I/O board .I
did not make this function.
it gives
bReady= true on events.

My question is that "CAN I USE member variable like this"
I means Can I use address of member variable to some function.

推荐答案

vsrajput写道:
vsrajput wrote:
我不是优秀的OOP程序员,试图实现我的在OOP中工作代码。


如果这只是一个很酷的学习方法。不要在工作中这样做

因为你不应该花太多时间来改变已经有效的代码。

我有类似这个类的东西。类数据记录器{
公共:
UINT端口;
BOOL bReady;


是否有任何指定bReady?


在您进行操作之前,下面的代码是什么样的?

Waitforevent(Port,INFINTE,& bReady)
if(bReady)
Where" Waitforevent"是我的I / O板的驱动程序.I
没有实现这个功能。
它给出了事件上的bReady = true。


尝试将其添加到构造函数中:

Datalogger :: Datalogger(UINT x,bool y):bReady(false){}

我的问题是我可以像这样使用成员变量
我的意思是我可以使用成员变量的地址来实现某些功能。
I am not good OOP programmer ,trying to implement my already working
code in OOP.
If that''s just a learning thing that''s cool. Don''t do that on the job
because you shouldn''t spend too much time changing code that already works.
I have somthing like this class.

class Datalogger{
public:
UINT Port;
BOOL bReady ;
Does anything assign bReady?

What did the following code look like before you OOP-ed it?
Waitforevent( Port , INFINTE , &bReady)
if(bReady) Where "Waitforevent" is fucntion came with driver of my I/O board .I
did not make this function.
it gives
bReady= true on events.
Try adding this to the constructor:

Datalogger::Datalogger(UINT x ,bool y): bReady(false) {}
My question is that "CAN I USE member variable like this"
I means Can I use address of member variable to some function.




是的,因为变量的寿命比调用Waitforevent()的时间长。

但是,你的变量现在可能包含垃圾,而Waitforevent()可能会读取
bReady'的价值,期待真假。


-

Phlip
http://c2.com/cgi/wiki?ZeekLand < - 不是博客!!!



Yes, because the variable lives longer than the call to Waitforevent().
However, your variable might now contain garbage, and Waitforevent() might
read bReady''s value and expect true or false.

--
Phlip
http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!


vs******@gmail.com 写道:
我有类似这样的课程。

类Datalogger {
公开:
UINT端口;
BOOL bReady;
数据记录器(UI NT x,bool y);
〜数据记录器();

bool LOpen();
bool LStatus();

};

一切都还行,直到bool LStatus();

bool LStatus()
.....
.....这里我有一堆东西;
但我在这里遇到问题

Waitforevent(Port,INFINTE,& bReady)
if(bReady)
{
.... ..
....一些东西;
......

}
}

其中Waitforevent是我的I / O板的驱动程序.I
没有实现这个功能。
它给了事件bReady = true。

我的问题是我可以像这样使用成员变量
我的意思是我可以使用成员变量的地址来实现某些功能。
I have somthing like this class.

class Datalogger{
public:
UINT Port;
BOOL bReady ;

Datalogger (UINT x ,bool y);
~Datalogger ();

bool LOpen ();
bool LStatus ();

};
Everything is OK till "bool LStatus ();"

bool LStatus ()
{
..... Here I have bunch of stuff;
but I get problem here

Waitforevent( Port , INFINTE , &bReady)
if(bReady)
{
......
....some stuff ;
......

}
}
Where "Waitforevent" is fucntion came with driver of my I/O board .I
did not make this function.
it gives
bReady= true on events.

My question is that "CAN I USE member variable like this"
I means Can I use address of member variable to some function.




当然。你遇到的问题是什么?


V

-

请删除资金''A'在通过电子邮件回复时

我没有回复最热门的回复,请不要问



Sure. What''s the problem you''re encountering?

V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask


vs ****** @ gmail.com 写道:
大家好

我有类似这类的东西。

类Datalogger {<公开:
UINT端口;
BOOL bReady;

数据记录器(UINT x,bool y);
〜数据记录器();

bool LOpen();
bool LStatus();

};

一切正常,直到bool LStatus();

bool LStatus()
.....
这里我有很多东西;
但我在这里遇到问题

Waitforevent(端口,INFINTE和& bRe ady)
if(bReady)
{
......
......有些东西;
......

}
}

Where" Waitforevent"是我的I / O板的驱动程序.I
没有实现这个功能。
它给了事件bReady = true。

我的问题是我可以像这样使用成员变量
我的意思是我可以使用成员变量的地址来实现某些功能。
Hi guys

I am not good OOP programmer ,trying to implement my already working
code in OOP.

I have somthing like this class.

class Datalogger{
public:
UINT Port;
BOOL bReady ;

Datalogger (UINT x ,bool y);
~Datalogger ();

bool LOpen ();
bool LStatus ();

};
Everything is OK till "bool LStatus ();"

bool LStatus ()
{
..... Here I have bunch of stuff;
but I get problem here

Waitforevent( Port , INFINTE , &bReady)
if(bReady)
{
......
....some stuff ;
......

}
}
Where "Waitforevent" is fucntion came with driver of my I/O board .I
did not make this function.
it gives
bReady= true on events.

My question is that "CAN I USE member variable like this"
I means Can I use address of member variable to some function.




是的你可以......


....但在这种情况下为什么?从你所写的内容来看,如果bReady是LStatus()的局部变量,那么
可能会更好。除非你需要在其他地方使用bReady中的值...


Dave



Yes you can...

....but in this case why? From what you have written, it looks like it
might be better if bReady was a local variable of LStatus(). Unless you
need to use the value in bReady somewhere else...

Dave

这篇关于在OOP中提供帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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