Using Template in friend class : <p>First of all, my teacher asked mу to do something like that. </p>

<p>I have a class of two-dimensional array: </p>

<pre><code>    #pragma once
    #include &lt;iostream&gt;
    #include "MyMaskedMassiv.h"

    template&lt;typename T&gt;
    class MyMaskedMassiv;

    template &lt;typename T&gt;
    class My2dMassiv{
    private:
        T* mas;
        int col;
        int str;
    public:
    ........
        friend class MyMaskedMassiv&lt;T&gt;;

        MyMaskedMassiv&lt;T&gt;&amp; operator()(My2dMassiv&lt;bool&gt;&amp; mask){
            MyMaskedMassiv&lt;T&gt; *maskMas = new MyMaskedMassiv&lt;T&gt;();
            maskMas-&gt;masiv = this;
            maskMas-&gt;mask = &amp;mask; 
            return *maskMas;
        }
    }
</code></pre>

<p>And as you can see another class "MyMaskedMassiv" that have links to the first one:</p>

<pre><code>    #pragma once
    #include "My2dMassiv.h"

    template &lt;typename U&gt;
    class My2dMassiv;

    template &lt;typename T&gt;
    class MyMaskedMassiv{
    private:
        My2dMassiv&lt;T&gt; *masiv;
        My2dMassiv&lt;bool&gt; *mask;
    public:
        friend class My2dMassiv&lt;T&gt;;
        friend class My2dMassiv&lt;bool&gt;;

        MyMaskedMassiv(){
            masiv = nullptr;
            mask = nullptr;
        }

        MyMaskedMassiv&amp; operator=(const T&amp; el){
            int s = masiv-&gt;str;
            int c = masiv-&gt;col;

            for(int i=0; i&lt;c; i++)
                for( int j=0; j&lt;s; j++)
                    if( this-&gt;mask-&gt;mas[i*s + j] == true)
                        this-&gt;masiv-&gt;mas[i*s + j] = el;  

        return *this;
        }
    }
</code></pre>

<p>So then I try to build I got an error: </p>

<pre><code>    My2dMassiv.h:11:8: error: ‘bool* My2dMassiv&lt;bool&gt;::mas’ is private

    ../src/myproject/MyMaskedMassiv.h:27:36: error: within this context
             if( this-&gt;mask-&gt;mas[i*s + j] == true)
</code></pre>

<p>So.. what am I doing wrong?</p>

<p>If you want to see full code, check here: <a href="https://github.com/Yarik2308/SystemProg/tree/master/Zadanie4/src/myproject" rel="nofollow noreferrer">GIT</a></p>
