창신다이 2006. 11. 23. 13:52

Q: 다음 프로그램에서 아레 TestFunc()와 TestFuncSecond()는 어느 class에 있는 함수가 불리겠는가?

class CBase {
public:
int m_base;
void TestFunc(void);
virtual void TestFuncSecond(void);
};

class CDerived : public CBase {
public:
void TestFunc(void);
virtual void TestFuncSecond(void);
virtual void TestFuncThree(void) { };
};

class COther : public CBase {
public:
int m_other;
void TestFunc(void);
virtual void TestFuncSecond(void);
};

class CAnother : public COther {
public:
int m_another;
void TestFunc(void);
virtual void TestFuncSecond(void);
};

//

void CBase::TestFunc()  { m_base = 3; }
void CDerived::TestFunc() { m_base = 3; }
void COther::TestFunc()  { m_base = 3; }
void CAnother::TestFunc() { m_base = 3; }

void CBase::TestFuncSecond()  { m_base = 3; }
void CDerived::TestFuncSecond() { m_base = 3; }
void COther::TestFuncSecond()  { m_base = 3; }
void CAnother::TestFuncSecond() { m_base = 3; }

int _tmain(int argc, _TCHAR* argv[])
{
CDerived *derived;
CAnother another;

derived = (CDerived *)&another;

derived->TestFunc();
derived->TestFuncSecond();

return 0;
}