
com_print_typeinfo 함수는 std::type_info 객체를 인자로 받기 때문에, 여러 타입의 정보를 동시에 출력하려면 std::type_info 객체를 생성하여 리스트나 벡터에 저장한 후, 반복문을 사용하여 각 객체의 정보를 출력하면 됩니다.
예를 들어, 다음과 같이 std::type_info 객체를 리스트에 저장한 후, 반복문을 사용하여 각 객체의 정보를 출력할 수 있습니다.
#hostingforum.kr
cpp
#include
#include
#include
int main() {
std::vector typeList;
// 여러 타입의 정보를 추가합니다.
typeList.push_back(typeid(int));
typeList.push_back(typeid(float));
typeList.push_back(typeid(std::string));
// 반복문을 사용하여 각 객체의 정보를 출력합니다.
for (const auto& type : typeList) {
std::cout << type.name() << std::endl;
}
return 0;
}
이 코드를 실행하면, int, float, std::string 타입의 정보가 출력됩니다.
또한, C++11부터는 std::type_index를 사용하여 여러 타입의 정보를 동시에 출력할 수 있습니다. std::type_index는 std::type_info의 인덱스 역할을 하며, std::type_info 객체를 인자로 받을 때, std::type_index를 사용하여 객체의 정보를 출력할 수 있습니다.
#hostingforum.kr
cpp
#include
#include
int main() {
// 여러 타입의 정보를 추가합니다.
std::type_index typeIndex1(typeid(int));
std::type_index typeIndex2(typeid(float));
std::type_index typeIndex3(typeid(std::string));
// 반복문을 사용하여 각 객체의 정보를 출력합니다.
for (const auto& type : {typeIndex1, typeIndex2, typeIndex3}) {
std::cout << type.name() << std::endl;
}
return 0;
}
이 코드를 실행하면, int, float, std::string 타입의 정보가 출력됩니다.
이러한 방법을 사용하여, com_print_typeinfo 함수를 사용하여 여러 타입의 정보를 동시에 출력할 수 있습니다.
2025-05-01 17:11