vendredi 24 août 2018

C++ can not pass object by constructor

Error message:

error C2248: 'SimReceivePortBase::SomeClass' : cannot access private member declared in class 'SomeClass'

What I'm trying to do:

I have a template which looks like this

template <typename T>
struct GenericPort
{
    T port;
    explicit GenericPort(const T& port) : port(port)
    {
    }
};

And I'm just trying to use it in this way:

GenericPort<SomeClass> port1(mySomeClass);

But for some weird reason, I receive each time that error message.

What I've try to do: I've try to use friend class like this.

template <typename T>
struct GenericPort
{
    friend class SomeClass;
    T port;
    explicit GenericPort(const T& port) : port(port)
    {
    }
};

Also I've try do add an operator= inside of my SomeClass and trying to do something like this.

GenericPort<SomeClass> port1;
port1.port = mySomeClass;

And still nothing change. Dose any of you have any idea?

Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire