E D R , A S I H C RSS

Run Time Type Information



1. RTTI

λ™μ μœΌλ‘œ λ§Œλ“€μ–΄μ§„ λ³€μˆ˜μ˜ νƒ€μž…μ„ λΉ„κ΅ν•˜κ³ , νŠΉμ • νƒ€μž…μœΌλ‘œ μƒμ„±ν•˜λŠ” 것을 κ°€λŠ₯ν•˜κ²Œ ν•œλ‹€. (μžλ°”μ—μ„œλŠ” instanceofλ₯Ό 생각해보면 될 λ“―)

MFCμ—μ„œλŠ” C++μ—μ„œ ν‘œμ€μœΌλ‘œ 이용되기 이전뢀터 맀크둜λ₯Ό μ΄μš©ν•œ λ°©λ²•μœΌλ‘œ 이것을 μ§€μ›ν–ˆμœΌλ©°, 아직도 κ·Έ μž”μž¬κ°€ λ‚¨μ•„μžˆλ‹€.

2. example

μ•„λž˜λŠ” RTTI의 μ“°μž„μƒˆλ₯Ό ν‘œν˜„ν•œ μΌμ˜ˆμ΄λ‹€.
~cpp
class base {
};

class derived : public base {
   int compare(derived &ref);
};

int my_comparison_method_for_generic_sort(base &ref1, base &ref2)
{
    derived d = dynamic_cast<derived &>(ref1);  // rtti used here
    // rtti enables the process to throw a bad_cast exception
    // if the cast is not successful
    return d.compare(dynamic_cast<derived &>(ref2));
}

μœ„μ—μ„œ 보듯이 클래슀의 ν˜•μ„ λΉ„κ΅ν•˜λŠ” 것이 κ°€λŠ₯ν•˜λ‹€.

3. RTTI in MFC


MFCμ—μ„œ CRuntimeClass ꡬ쑰체, DECLARE_DYNAMIC, IMPLEMENT_DYNAMIC, DECLARE_DYNCREATE, IMPLEMENT_DYNCREATE, RUNTIME_CLASS λ₯Ό μ΄μš©ν•΄μ„œ κ΅¬ν˜„ν•˜κ³  μžˆλ‹€.
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:27:56
Processing time 0.0090 sec