常见问题我为什么看到它? [英] faq why I see it?

查看:59
本文介绍了常见问题我为什么看到它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我们知道,静态成员viarable是与

类相关联的对象,而不是与该类对象相关联的对象。当我们调试代码时,我们

看不到某个特定类的成员的价值,但对我来说,我看到了它,它让我感到困惑。

我的代码出了什么问题?


class CSegment

{

public:

....

private:

....

static unsigned int m_numsegment;


};


CSegment :: CSegment(无效)

:m_pointlist(0)

,m_index (0)

,m_createdirection(true)

{

}


....


class CborderView:public CView

{

....

private:

....

vector< CSegmentm_mylinelist;

....


};


当我调试代码时,我在m_mylinelist的每个元素中都看到了m_numsegment的值

,为什么?


非常感谢。

解决方案

在C ++ Primer,4第四版作者:Stanley B. Lippman,Jos¨| e Lajoie,

Barbara E. Moo 12.6。静态类成员

我尝试代码,我看不到

类静态成员的价值。


fcvcnet < fc ***** @163.comD'è????¢D ???:et**********@news.cn9 9.com ...
< blockquote class =post_quotes>


我们知道,静态成员viarable是一个与

类相关联的对象,而不是与那个班。当我们调试代码时,我们

看不到某个特定类的成员的价值,但对我来说,我看到了它,它让我感到困惑。

我的代码出了什么问题?


class CSegment

{

public:

...

私人:

...

static unsigned int m_numsegment;


};


CSegment :: CSegment(无效)

:m_pointlist(0)

,m_index(0 )

,m_createdirection(true)

{

}


...


class CborderView:public CView

{

...

private:

...

vector< CSegmentm_mylinelist;

...


};

当我调试代码时,我在m_mylinelist的每个

元素中看到m_numsegment的值,为什么?


非常感谢。



2007-03-14 08:47,fcvcnet写道:




我们知道,静态成员viarable是与

类关联的对象,而不是与该类的对象。当我们调试代码时,我们

看不到某个特定类的成员的价值,但对我来说,我看到了它,它让我感到困惑。

我的代码出了什么问题?



嗯,这完全取决于调试器供应商选择要显示的内容和

什么不是,标准不定义这样的铃声。但对我来说,这是非常正常的,你可以看到一个类的静态成员,毕竟他们是这个类的成员。或者另一种看待它的方式,静态

成员是在

类的每个实例中具有相同值的成员,除了这个特性之外(差不多)和其他任何成员一样。

所以调试人员将它显示为另一个

成员非常方便。


所以你的代码没有任何问题(除非每个对象的静态

成员的价值不同),而是你的期望

代码错了。


-

Erik Wikstr?m


谢谢。


但是我看到了这个:


m_mylinelist -

- [0]

+ m_pointlist

m_index

...

m_numsegment 5.< ---这是静态的
成员来自CSegment类的经纪人

- [1]

+ m_pointlist

m_index

...

m_numsegment 5.

- [2]

+ m_pointlist

m_index

...

m_numsegment 5.

..... ..

我使用vs2005,使用相同的工具,我调试C ++ Primer的代码,第四版

版本作者:Stanley B. Lippman,JoséeLajoie,Barbara E. Moo 12.6。静态

班级成员


班级帐号{

public:

....

私人:

....

静态双倍利率;

....

};


我用它,

vector< Accountac1(5);

在调试中

ac1 -

- [0]

+所有者

账号

(无静电double interestRate)

- [1]

+所有者

账户

(无静态双倍利率)

- [2]

+所有者

账户

(无静态双倍利率)

.......

我无法看到静态成员可以通过|| static double interestRate

|| 。


为什么?


非常感谢你。



Hi,
As we know, a static member viarable is an object associated with the
class, not with the objects of that class. And when we debug the code, we
can not see the value of the member of some particular class, but to me, I
see it, it puzzled me.
What is wrong with my code?

class CSegment
{
public:
....
private:
....
static unsigned int m_numsegment;

};

CSegment::CSegment(void)
: m_pointlist(0)
, m_index(0)
, m_createdirection(true)
{
}

....

class CborderView : public CView
{
....
private:
....
vector <CSegmentm_mylinelist;
....

};

And when I debug the code , I see the value of m_numsegment in every element
of the m_mylinelist, why?

Thanks a lot.

解决方案

And in book C++ Primer, Fourth Edition By Stanley B. Lippman, Jos¨|e Lajoie,
Barbara E. Moo 12.6. static Class Members
I try the code , and I can not see the value of the static member of a
class.

"fcvcnet" <fc*****@163.comD′è????¢D???:et**********@news.cn9 9.com...

Hi,
As we know, a static member viarable is an object associated with the
class, not with the objects of that class. And when we debug the code, we
can not see the value of the member of some particular class, but to me, I
see it, it puzzled me.
What is wrong with my code?

class CSegment
{
public:
...
private:
...
static unsigned int m_numsegment;

};

CSegment::CSegment(void)
: m_pointlist(0)
, m_index(0)
, m_createdirection(true)
{
}

...

class CborderView : public CView
{
...
private:
...
vector <CSegmentm_mylinelist;
...

};

And when I debug the code , I see the value of m_numsegment in every
element of the m_mylinelist, why?

Thanks a lot.



On 2007-03-14 08:47, fcvcnet wrote:

Hi,
As we know, a static member viarable is an object associated with the
class, not with the objects of that class. And when we debug the code, we
can not see the value of the member of some particular class, but to me, I
see it, it puzzled me.
What is wrong with my code?

Well, it''s really up to the debugger vendor to choose what to show and
what not to, the standard does not define such tings. But to me it''s
quite normal that you can see the static members of a class, after all
they are a member of the class. Or another way to look at it, the static
member is a member that has the same value in every instance of the
class, except for this peculiarity it''s (almost) like any other member.
So it''s quite convenient for the debugger to display it as just another
member.

So there''s nothing wrong with your code (unless the value of the static
member is different for each object) but rather it''s your expectations
of the code that are wrong.

--
Erik Wikstr?m


Thank you.

But I see this:

m_mylinelist --
--[0]
+ m_pointlist
m_index
...
m_numsegment 5. <--- this is static
member viarabe of class CSegment
--[1]
+ m_pointlist
m_index
...
m_numsegment 5.
--[2]
+ m_pointlist
m_index
...
m_numsegment 5.
.......
I use vs2005, use the same tools, I debug the code of C++ Primer, Fourth
Edition By Stanley B. Lippman, Josée Lajoie, Barbara E. Moo 12.6. static
Class Members

class Account {
public:
....
private:
....
static double interestRate;
....
};

I used it ,
vector <Accountac1(5);
In debug
ac1 --
--[0]
+owner
account
(no static double interestRate )
--[1]
+owner
account
(no static double interestRate )
--[2]
+owner
account
(no static double interestRate )
.......
All I can not see the static member viarable || static double interestRate
|| .

Why?

Thanks you very much.



这篇关于常见问题我为什么看到它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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