考考你的C++水平
Posted 力为
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了考考你的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);
}
以上是关于考考你的C++水平的主要内容,如果未能解决你的问题,请参考以下文章
如何使我们的水平达到世界顶级的水平?——你的老师就在你的面前