Feb 21, 2005

BCB or VS2003?

Oh my god.
I spent so much time on compiling my project by MS Visual Studio .Net 2003!
I used BCB 6 before. And the project is done.
DDJ said that Intel C++ Compiler (ICC) is the fastest compiler. OK, but it must run with Visual C++ 6 or above!
NCTU bought the right of using so many MS products in school. Thus I have VS2003.
At first, it's cannot be compiled by VS2003! After a lot of settings are done, it's OK.
Then, it's cannot be compiled by ICC! A sucking fatal error : Internal error during pass 2.
Who knows what happened in its pass 2?
I found that the error may be caused by mspdb71.dll but I don't know why.
Thanks for the great help of MSDN. From the document, the mspdb71.dll seems only used in debug mode.
Change the configuration to Release, it's OK!!
But the built EXE file cannot run....orz....
I still have no idea. I DO NOT want to know why! ICC really sucks!

I feel that the help document of BCB6 is better than MSDN....
Some examples in MSDN are too complex, and,
there is no easy example about _beginthreadex().

It's a ....bad story....

Feb 1, 2005

Virtual destructor

Both constructor and copy constructor cannot be virtual. Destructor could better be virtual.
Consider two classes: Base and Derived:

class Base{

public:

Base(){cout<<"Base called."<

~Base(){ cout<<"Base deleted."<

}

class Derived:public Base{

public:

Derived(){ cout << "Derived called." <<>

~Derived() { cout << "Derived deleted." <<>

}


Now if we delete a Derived object, then we will get
Base called.
Derived called.
Base deleted.

The reason is that the Derived class uses the destructor of Base class. Therefore, we use the keyword "virtual" in front of the destructor of Base class: virtual ~Base(). We will get
Base called.
Derived called.
Derived deleted.
Base deleted.

Which is the correct result.
When a derived class has its own behavior in function foo() and foo() is existed in its base class without virtual, program will not execute foo() in derived class but in base class. If foo() is virtual, foo() of derived will be executed correctly.
Therefore, destructor should always be virtual, isn't it?