Sep 18, 2009

virtual methods and polymorphism

Today I had an interview. One of questions was about polymorphism in C++. The questions was whether we need to have "virtual" keyword in order to use polymorphism in C++. The correct answer is that C++ doesn't allow any methods to be used as polymorphism if it is not virtual method.

The confusion came from Java syntax, because every methods in Java are virtual methods. Although it is an understandable mistake for Java programmers, it should be always clear for C++ programmers.

Let's see an example here:
#include windows.h

class BaseClass
{
public:
void printSome() { OutputDebugStr( L"Base\n" ); }
};

class DerivedClass : public BaseClass
{
public:
void printSome() { OutputDebugStr( L"Derived\n" ); }
};

int _tmain(int argc, _TCHAR* argv[])
{
BaseClass * const obj = new DerivedClass();
obj->printSome();
delete obj;

return 0;
}
Which message should we expect to see? A correct answer is "Base" not "Derived", because it doesn't have "virtual" keyword.

The guy who raised this question to me was evaluating my technical skills on my interview. I doubt whether he graded me fairly. I wish he can find this article and correct his misunderstanding.

Sep 10, 2009

Billiard game

I have spent about 5 weeks for this personal project. The purpose of this project is to show my technical fluency. I have chosen to develop a simple billiard game with Collada, PhysX, and Shader programs.

Requirement:
  • DirectX 9 end-user runtime
  • Graphic card that can support Shader Model 2. ( Pixel shader 2.0 will be enough )
  • PhysX must be installed.
  • OpenAL must be installed.
Demo video:


Source code is available on Google Code: http://code.google.com/p/mybilliard01

Used technique:
  • PhysX
  • Collada
  • DirectX 9
  • HLSL
  • OpenAL
  • Microsoft C++/CLI unit testing framework
  • std::tr1
Note
The balls colliding to each other under Physical calculations. Shadow is drawn by shadow map. The graphic model data are from 3DS Max through Collada XML standard. Sound is powered by OpenAL.

Screen shots
The captured video lost some graphical details, so that I like to attach some screen shots here. Click each image to enlarge it.



*PS : Background needs to be added soon.