GCC cannot support local classes together with template.
Jim King
jim_king_2000@163.com
Fri Mar 13 04:05:00 GMT 2009
Hi everyone:
The following code cannot be compiled by GCC 4.3.3.
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int main()
{
class PrintOne : unary_function<int, void>
{
public:
result_type operator()(argument_type i)
{
wcout << i << L'\n';
}
};
int a[20] = {0, 0, 0, 0, 0};
for_each(a, a + 20, PrintOne());
return 0;
}
The error message is:
test.cpp:22: error: no matching function for call to `for_each(int[20],
int*, main()::PrintOne)'
If we move class PrintOne outside or do not use template function, the
compilation will succeed.
Is the behavior a bug or as design? Thanks.
--
View this message in context: http://www.nabble.com/GCC-cannot-support-local-classes-together-with-template.-tp22489866p22489866.html
Sent from the gcc - libstdc++ mailing list archive at Nabble.com.
More information about the Libstdc++
mailing list