以下repo编译好:
#include <tuple>
#include <vector>
class Foo
{
public:
typedef std::tuple<int, int> foo_type;
std::vector<foo_type>::iterator Find() {
return Listeners.begin();
}
std::vector<foo_type> Listeners;
};
int main()
{
Foo foo;
auto i = foo.Find();
}
但是当我在P,Q上模拟元组时,就像在下面的repo中一样,我得到了这个错误:
语法错误:缺少';'在标识符'查找'之前
#include <tuple>
#include <vector>
template<typename P, typename Q>
class Foo
{
public:
typedef std::tuple<P, Q> foo_type;
std::vector<foo_type>::iterator Find() {
return Listeners.begin();
}
std::vector<foo_type> Listeners;
};
int main()
{
Foo<int, int> foo;
auto i = foo.Find();
}
答案 0 :(得分:2)
您在这里错过typename
:
typename std::vector<foo_type>::iterator Find() {
^^^^^^^^
return Listeners.begin();
}
有关更详细的说明,请参阅Where and why do I have to put the "template" and "typename" keywords?