考考你的C++水平

指出执行NoSwitchTest函数的执行结果,并说明执行过程。

enum FACE_TYPE
{
 FACE_XY,
 FACE_XZ,
 FACE_YZ
};

template<int faceType>
class Face
{
public:
 enum {FACE_TYPE = faceType};
 virtual void Draw() = 0;
};

class FaceOp
{
public:
 template<int type>
 void actionSpecial(Face<type>& T)
 {
  _actionSpecial(T);
 }
 template<int type>
 void actionCommon(Face<type>& T)
 {
  std::cout << "this is the action common/n";
 }
private:
 void _actionSpecial(Face<FACE_XY>)
 {
  std::cout << "   this is the action FACE_XY/n";
 }
 void _actionSpecial(Face<FACE_XZ>)
 {
  std::cout << "   this is the action FACE_XZ/n";
 }
 void _actionSpecial(Face<FACE_YZ>)
 {
  std::cout << "   this is the action FACE_YZ/n";
 }
};

class FaceXY : public Face<FACE_XY>
{
public:
 void Draw()
 {
  std::cout << "Draw FACE_XY/n";
 }
};

class FaceXZ : public Face<FACE_XZ>
{
public:
 void Draw()
 {
  std::cout << "Draw FACE_XZ/n";
 }
};

class FaceYZ : public Face<FACE_YZ>
{
public:
 void Draw()
 {
  std::cout << "Draw FACE_YZ/n";
 }
};

inline void NoSwitchTest()
{

 FaceXY  faceXY;
 FaceXZ  faceXZ;
 FaceYZ  faceYZ;
 FaceOp  faceOp;

 faceOp.actionSpecial(faceXY);
 faceOp.actionSpecial(faceXZ);
 faceOp.actionSpecial(faceYZ);

 faceOp.actionCommon(faceXY);
 faceOp.actionCommon(faceXZ);
 faceOp.actionCommon(faceYZ);
}

posted on 2005-09-21 16:55  张大大123  阅读(93)  评论(0编辑  收藏  举报

导航