1

I am trying to find a way to declare a function in specific manner. The code looks like this:

template<typename T>
    class Outer {
        class Inner {
            public:
            friend void doSth(const typename Outer<T>::Inner& inner1, const typename Outer<T>::Inner& inner2);
    }
}

What I am trying to do is to define this function outside declaration. I can easily do it inside but whenever I try to define it outside VS2013 yields linker error. Could you help me with this problem?

Yes, I tried predefining these methods before inner class definition but nothing actually works for me

EDIT:

template<typename T>
class Outer
{
public:
    class Inner;
};

template<typename T> void doSth(typename Outer<T>::Inner&ob1, typename Outer<T>::Inner& ob2);
template<typename T>
class Outer<T>::Inner
{
    friend void doSth<>(Inner& ob1, Inner& ob2);
};

template<typename T>
void doSth(typename Outer<T>::Inner&ob1, typename Outer<T>::Inner& ob2)
{
    cout << "sth";
}

int main()
{
    Outer<int>::Inner ob;
    doSth(ob, ob);
    return 0;
}

For example this approach results in an error.

1>main.obj : error LNK2019: unresolved external symbol "void __cdecl doSth(class Outer<int>::Inner &,class Outer<int>::Inner &)" (?doSth@@YAXAAVInner@?$Outer@H@@0@Z) referenced in function _main
1>Project.exe : fatal error LNK1120: 1 unresolved externals
bottaio
  • 4,963
  • 3
  • 19
  • 43
  • 4
    *"whenever I try to define it outside VS2013 yields linker error."* Please show us your attempts and the linker error. An [MCVE](http://stackoverflow.com/help/mcve) would be much appreciated. – dyp Apr 22 '15 at 20:27
  • 1
    Scrape `typename Outer::` in the friend declaration. –  Apr 22 '15 at 20:33
  • The `doSth` friend is not a function template. It is an ordinary function whose parameters are class template specializations. See the answers to the duplicate question. – dyp Apr 22 '15 at 23:00

0 Answers0