This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

GCC cannot support local classes together with template.


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]