0

I've nested a template in a class message which usually contains a subclass of message, but if I want it contain message itself, I run into problems of conflicting ctor overloads. (It would be good if I could somehow get it to ignore one of the conflicting methods, but I don't know how.) So I try to make a specialization of the messsage containee, but then I get

explicit specialization in non-namespace scope 'class message'

I've researched how to deal with errors like that (like here, here and here) but I can't figure out how to shoehorn those solutions into my problem.

class message {
    template<class T>
    class sptrTemplate : public QSharedPointer<T>
    {
    public:
        sptrTemplate() : QSharedPointer<T>() {}
        sptrTemplate(T *msg_ptr) : QSharedPointer<T>(msg_ptr) {}
        sptrTemplate(message *msg_ptr) : QSharedPointer<T>(static_cast<T *>(msg_ptr)) {}
    };
};

Remember, T is usually a subclass of message. The only exception is when T is message. Then, there's an obvious conflict between the 2nd and 3rd ctor. But if I try specializing with

    template <>
    class sptrTemplate<message> : public QSharedPointer<message>
    {
    public:
        sptr() : QSharedPointer<message>() {}
        sptr(message *msg_ptr) : QSharedPointer<message>(msg_ptr) {}
    };

then I get that compiler error, and I can't figure out how to deal with that.

Constructor
  • 7,273
  • 2
  • 24
  • 66
Opux
  • 702
  • 1
  • 10
  • 30
  • 2
    Your link here https://stackoverflow.com/a/5777270/597607 has the exact solution to the problem. Note that you have to use `message::sptrTemplate` when specializing outside the `message`class. – Bo Persson Dec 21 '17 at 15:14
  • @BoPersson Funny, I tried that before, and it didn't work. It seems I didn't know how to properly express the namespace. – Opux Dec 21 '17 at 15:23

0 Answers0