Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

why can’t I use pLast to access a field of the Data class via ->

$
0
0

why can’t I use pLast to access a field of the Data class via operator ->.

    template<typename _Ty>    class Data {    public:    Data(_Ty _data) : pNext(nullptr), pPrev(nullptr), data(_data) {};    ~Data() {};    private:    _Ty data;    std::unique_ptr<Data> pNext;    std::unique_ptr<Data> pPrev;    };    template<class _Ty>    class queue {    public:    queue() : pFirst(nullptr), pLast(nullptr) {};    ~queue() {};    bool isEmpty() {        return pFirst == nullptr;    };    void push_back(_Ty value) {        std::shared_ptr<Data<_Ty>> pData = std::make_shared<Data>(value);        if (isEmpty()) {            pFirst = pData;            pLast = pData;            return;        }        pLast = pData;    }    public: static int count;    public:       std::shared_ptr<Data<_Ty>> pFirst;       std::shared_ptr<Data<_Ty>> pLast;    };

I can access a field of the Data class only if my pLast is a regular pointer and not shared or unique. but I need something that I can access through a smart pointer


Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>