У меня странная проблема с шаблонами C ++, и я не понимаю, почему не работает следующий код:
#include <iostream>
template <typename A, typename B>
class TypePair {
public:
typedef A First;
typedef B Second;
};
template <typename P>
class Foo {
public:
Foo(P::First f, P::Second) {
std::cout
<< "first = " << f << std::endl
<< "second = " << s << std::endl;
}
};
int main(int argc, char **argv) {
Foo<TypePair<int, double> > foo(42, 23.0);
return 0;
}
Код выдает следующие ошибки:
$ g++ templates.cpp -o templates
templates.cpp:14: error: expected ‘)’ before ‘f’
templates.cpp: In function ‘int main(int, char**)’:
templates.cpp:23: error: no matching function for call to ‘Foo<TypePair<int, double> >::Foo(int, double)’
templates.cpp:12: note: candidates are: Foo<TypePair<int, double> >::Foo()
templates.cpp:12: note: Foo<TypePair<int, double> >::Foo(const Foo<TypePair<int, double> >&)
Для меня код выглядит вполне нормально, но у g ++, очевидно, есть свое мнение ^^ Есть идеи?
Себастьян