我现在想让一些类共享一位图,我写成这种形式。
class myClass
{
private:
 ……
 static CBitmap m_pic;
 static CString m_str;
};静态变量是不是一定要初始化???
m_str初始化还好办
CString myClass::m_str="abcd";可是m_pic呢??好像根本就没有"="操作!!!咋办

解决方案 »

  1.   

    #include <iostream>using namespace std;class Point
    {
    private:
    static int count;public:
    void countVal()
    {
    cout<<count<<endl;
    }
    void operator =(int b)
    {
    count=b;
    }
    };int Point::count =1;class Rect
    {
    private:
    static Point a;
    public:
    void countVal()
    {
    a.countVal();
    }

    };void Rect::a=5;void main()
    {

    Point a;
    a.countVal();
    a=8;
    a.countVal(); Rect b;
    b.countVal();}
      

  2.   

    main()上的void Rect::a=5;是问题的关键!!!!!!!!!!!!!如何初始化它