mercredi 1 mars 2017

Making a class or struct to be friend of all template instantiated class?

#include <iostream>

using namespace std;

struct s1;

template <typename... type>
class Base : public type::inner...
{
    friend struct s1;

};

class Test;

struct s1
{
    template <typename... type>
    friend class Base;

    friend class Test;

    private:
    struct inner {

    int member1;
    int member2;
    };
};

struct s2
{
    struct inner {

    int member3;
    int member4;
    };
};

struct Test : public s1::inner, public s2::inner
{

};

int main()
{
    Base<s1, s2> base;
    base.member1 = 0;

    Test t;
    t.member3 = 22;

    cout << "Hello world!" << endl;
    return 0;
}

When I tried to compile the above code I am getting the below error

In instantiation of 'class Base': error: 'struct s1::inner' is private

However the class Test is compiled successfully without error. I want to make the template class named base to be friend of struct s1. How do I do that?

Aucun commentaire:

Enregistrer un commentaire