我通过未定义类型获得了迭代器:
for (typename Type::const_iterator hayStackIterator = hayHeap.begin(); hayStackIterator != hayHeap.end(); ++hayStackIterator) {
//some inner logic
}
如果知道我的 *hayStackIterator
是什么类型,以便能够根据此信息修改内部逻辑,那就太好了……是否有一些简单的函数可以实现这样的功能?
if (*hayStackIterator.isInstanceOf(vector<string>){
//do something
} else if (*hayStackIterator.isInstanceOf(string){
//do something else
}
我可以使用这些 includes
:
#include <cctype>
#include <iostream>
#include <iomanip>
#include <set>
#include <list>
#include <map>
#include <vector>
#include <queue>
#include <string>
最佳答案
将内部逻辑放在一个函数中,并重载该函数:
void innerLogic(vector<string> const& vec) {
//do something
}
void innerLogic(string const& str) {
//do something else
}
void loop() {
for (typename Type::const_iterator hayStackIterator = hayHeap.begin();
hayStackIterator != hayHeap.end();
++hayStackIterator)
{
innerLogic(*hayStackIterator);
}
}
关于c++ - 如何确定我输入的是什么类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16116327/