Thread: help!
View Single Post
  #4 (permalink)  
Old August 24th, 2004, 10:21 AM
nw61 nw61 is offline
Authorized User
 
Join Date: May 2004
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you,Ankur.Yes,char * is OK.
I think the program below can make us more clearly of how VC6.0 works.
class AA
{
public:

    AA() : v(0)
    {
        ++count;
        cout << "Default constructor" << endl;
    }
    AA(int d) : v(d)
    {
        ++count;
        cout << "constructor" << endl;
    }
    ~AA()
    {
        --count;
    }
    void Show()
    {
        cout << "v=" << v << "\tcount=" << count << endl;
    }

private:
    int v;
    static int count;
};

int AA::count = 0;


AA a(5);
extern AA a; // A new object a is generated
int main()
{
    {
        AA b(4);
        b.Show(); // Now three objects have been generated.
    }
    a.Show();
}

// The result
constructor
Default constructor
constructor
v=4 count=3
v=0 count=2
Press any key to continue


So we can see clearly that VC6 generated a new object when running to
the code of "extern string str" and the former object was covered.



niuwei
Reply With Quote