Pergunta

I have a problem with the following situation: a library (CardReader) implements the ISO7816 protocol and communicates with a smart card (implemented by me).

I have to implement a proprietary protocol that use this library.

In CardReader there are the following classes APDURequest and APDUResponse. and the CardReader class implements all the functions to send and receive these messages.

class APDUResonse
{
public:   
    /* ctor, copy ctor, move ctor, copy =, and move = operators. */
    //...
    int statusWord() const { return ...; }
    int sw1() const { return ...; }
    int sw2() const { return ...; }   
};

On the other hand in my software I have a hierarchy independent implentare the messages to and from the smart card. This is the interface of base class:

enum class MessageResKind { /* ... */ };

class IMessageRes
{
public:
    virtual ~IMessageRes() {};
    virtual int statusWord() const = 0;
    virtual int sw1() const = 0;
    virtual int sw2() const = 0;
    virtual MessageResKind kind() const = 0;       
    virtual void print( std::ostream& ) = 0;
};

Now my doubt is how to derive specialized class... my first attempt was:

class ADMessageResATR : public IADMessageRes, private iso7816::APDUResponse
{
public:

    // import iso7816::APDUResponse ctor
    using iso7816::APDUResponse::APDUResponse;

    using iso7816::APDUResponse::sw1;
    using iso7816::APDUResponse::sw2;
    using iso7816::APDUResponse::statusWord;

    ADMessageResKind kind() const
    {
        return ADMessageResKind::ATR;
    }

    void print() const {}
};

But I've compile time error: unable to instantiate abstract class ADMessageResATR: statusWord, sw1 and sw2 abstract

Foi útil?

Solução

not sure what you are trying to achieve but if you want to expose the interface and use the library implementation, can you do something like this:

class ADMessageResATR : public IADMessageRes, private iso7816::APDUResponse
{
public:

    int sw1() const {return iso7816::APDUResponse::sw1();}
...
};
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top