RTTI - Gakgu/Gakgu.github.io GitHub Wiki
Run-Time Type Information. ์ค์๊ฐ ํ์ ์ ๋ณด๋ค. ์คํ ์ค ํ์ ์ ๋ณด๊ฐ ํ์ํ ๋ ์ฌ์ฉํ๋ค. ์ปดํ์ผ๋ฌ์์ RTTI๊ธฐ๋ฅ์ ์๋์ผ๋ก ์ผ์ผํ๋ ๊ฒฝ์ฐ๊ฐ ์๋ค.
#include <typeinfo>
class type_info {
...
public:
const char* name() const;
const char* raw_name() const;
int operator==(const type_info& rhs) const;
int operator!=(const type_info& rhs) const;
...
};
typeid(๋ณ์).name();
typeid(๋ณ์).raw_name();
๊ฒฐ๊ณผ๋ฌผ์ ์ปดํ์ผ๋ฌ๋ง๋ค ๋ค๋ฅด๋ฉฐ ์ฌ๊ธฐ ์์ ์์๋ gcc๊ธฐ๋ฐ์ ๊ฒฐ๊ณผ๋ฌผ์ ์์๋ณธ๋ค.
ํ์
์ ์ฒซ ์ํ๋ฒณ๋ง ๋ฆฌํด
ex) typeid(int).name()์ผ ๊ฒฝ์ฐ i ๋ฆฌํด
ํด๋์ค ์ด๋ฆ์ ๊ฐ์ + ํด๋์ค์ ์ด๋ฆ
ex) typeid(class gakgu)name()์ผ ๊ฒฝ์ฐ 5gakgu ๋ฆฌํด
P + ์๋ ํ์
์ ๋ฆฌํด๊ฐ
ex) typeid(class gakgu*).name()์ผ ๊ฒฝ์ฐ P5gakgu ๋ฆฌํด
์ปดํ์ผ๋ฌ๋ง๋ค ๊ฒฐ๊ณผ๊ฐ์ด ๋ค๋ฅด๋ฏ๋ก typeid๋ฅผ ์ฌ์ฉํ ๋์๋ class type_info์ ๋น๊ต ์ฐ์ฐ์๋ง ์ฌ์ฉํ๋ค.
if(typeid(int) == type(char))
...;