本文介绍了常见问题我为什么看到它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我们知道,静态成员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的值 ,为什么? 非常感谢。 解决方案 嗯,这完全取决于调试器供应商选择要显示的内容和 什么不是,标准不定义这样的铃声。但对我来说,这是非常正常的,你可以看到一个类的静态成员,毕竟他们是这个类的成员。或者另一种看待它的方式,静态 成员是在 类的每个实例中具有相同值的成员,除了这个特性之外(差不多)和其他任何成员一样。 所以调试人员将它显示为另一个 成员非常方便。 所以你的代码没有任何问题(除非每个对象的静态 成员的价值不同),而是你的期望 代码错了。 - Erik Wikstr?m Hi,As we know, a static member viarable is an object associated with theclass, not with the objects of that class. And when we debug the code, wecan not see the value of the member of some particular class, but to me, Isee 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 elementof the m_mylinelist, why?Thanks a lot. 解决方案Well, it''s really up to the debugger vendor to choose what to show andwhat not to, the standard does not define such tings. But to me it''squite normal that you can see the static members of a class, after allthey are a member of the class. Or another way to look at it, the staticmember is a member that has the same value in every instance of theclass, except for this peculiarity it''s (almost) like any other member.So it''s quite convenient for the debugger to display it as just anothermember.So there''s nothing wrong with your code (unless the value of the staticmember is different for each object) but rather it''s your expectationsof the code that are wrong.--Erik Wikstr?m 这篇关于常见问题我为什么看到它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!