2

Can someone explain to me why this does not compile and how should I write it correctly?

#include <iostream>

using namespace std;

template <typename T>
struct Foo
{
    template <typename U>
    struct Bar
    {
    };
};

template <typename T, typename U>
void func(Foo<T>::Bar<U>& lhs)
{
    cout << "working" << endl;
}

int main()
{
    Foo<int>::Bar<char> a;
    func(a);

    return 0;
}

I get the following compiler error:

main.cpp:23:19: error: variable or field ‘func’ declared void  
void func(Foo<T>::Bar<U>& lhs)
463035818_is_not_an_ai
  • 109,796
  • 11
  • 89
  • 185
rozina
  • 4,120
  • 27
  • 49
  • It doesn't compile *now* because ["Where and why do I have to put the “template” and “typename” keywords?"](https://stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-the-template-and-typename-keywords) It will not compile afterwards because ["What is a nondeduced context?"](https://stackoverflow.com/questions/25245453/what-is-a-nondeduced-context) – StoryTeller - Unslander Monica Nov 07 '18 at 15:17

0 Answers0