Template method applied to template object
Hi all, The following lines don't compile with g++ (4.3.2) whereas it's ok with msvc 9. struct Foo { template<class T> unsigned int foo() const { return sizeof(T); } }; struct OtherFoo { template<class T> void f(const T& t) { t.foo<double>(); } }; int main() { Foo foo; OtherFoo other; other.f<Foo>(foo); return 0; } The ouput is : test.cpp: In member function ‘void OtherFoo::f(const T&)’: test.cpp:17: erreur: expected primary-expression before ‘double’ test.cpp:17: erreur: expected `;' before ‘double’ Does anybody know a workaround ? Thanks, Adrien
AMDG Adrien Chauve wrote:
The following lines don't compile with g++ (4.3.2) whereas it's ok with msvc 9.
struct OtherFoo { template<class T> void f(const T& t) { t.foo<double>(); } };
The ouput is : test.cpp: In member function ‘void OtherFoo::f(const T&)’: test.cpp:17: erreur: expected primary-expression before ‘double’ test.cpp:17: erreur: expected `;' before ‘double’
Does anybody know a workaround ?
t.template foo<double>(); This is required by the standard. msvc is being lax. In Christ, Steven Watanabe
Hi,
The following lines don't compile with g++ (4.3.2) whereas it's ok with msvc 9.
struct Foo { template<class T> unsigned int foo() const { return sizeof(T); }
};
struct OtherFoo { template<class T> void f(const T& t) { t.foo<double>(); }
}; [snip] The ouput is : test.cpp: In member function 'void OtherFoo::f(const T&)': test.cpp:17: erreur: expected primary-expression before 'double' test.cpp:17: erreur: expected `;' before 'double'
Does anybody know a workaround ?
The following works for me: --- foo.cpp.old 2009-03-03 10:01:21.086297500 -0800 +++ foo.cpp 2009-03-03 10:00:26.471330500 -0800 @@ -14,7 +14,7 @@ template<class T> void f(const T& t) { - t.foo<double>(); + t.template foo<double>(); } }; HTH, -Ossama
Thanks a lot for both answers !
On Tue, Mar 3, 2009 at 19:09, Othman, Ossama
Hi,
The following lines don't compile with g++ (4.3.2) whereas it's ok with msvc 9.
struct Foo { template<class T> unsigned int foo() const { return sizeof(T); }
};
struct OtherFoo { template<class T> void f(const T& t) { t.foo<double>(); }
}; [snip] The ouput is : test.cpp: In member function 'void OtherFoo::f(const T&)': test.cpp:17: erreur: expected primary-expression before 'double' test.cpp:17: erreur: expected `;' before 'double'
Does anybody know a workaround ?
The following works for me:
--- foo.cpp.old 2009-03-03 10:01:21.086297500 -0800 +++ foo.cpp 2009-03-03 10:00:26.471330500 -0800 @@ -14,7 +14,7 @@ template<class T> void f(const T& t) { - t.foo<double>(); + t.template foo<double>(); }
};
HTH, -Ossama _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Adrien Chauve wrote:
Hi all,
The following lines don't compile with g++ (4.3.2) whereas it's ok with msvc 9.
struct Foo { template<class T> unsigned int foo() const { return sizeof(T); }
};
struct OtherFoo { template<class T> void f(const T& t) { t.foo<double>(); }
};
int main() { Foo foo; OtherFoo other; other.f<Foo>(foo);
return 0; }
The ouput is : test.cpp: In member function ‘void OtherFoo::f(const T&)’: test.cpp:17: erreur: expected primary-expression before ‘double’ test.cpp:17: erreur: expected `;' before ‘double’
Does anybody know a workaround ?
Is this a C++ Boost question? - Volodya
participants (4)
-
Adrien Chauve
-
Othman, Ossama
-
Steven Watanabe
-
Vladimir Prus