mardi 28 mai 2019

How to define a static generic member

I get this error when trying to compile the program:

minpriorityqueue.cpp:4:36: error: expected expression std::map <MinPriorityQueue<G>::node*,int> MinPriorityQueue<G>::positions = ;

and it has the '^' symbol under the comma

// graph.h
#include "minpriorityqueue.h"
#include "node.h"
#include "edge.h"
class Traits {
    public:
        typedef char N;
    typedef int E;
};

template <typename Tr>
class Graph {
    public:
        typedef Graph<Tr> self;
        typedef MinPriorityQueue<self> min_priority_queue;
        typedef Node<self> node;

        struct u {
            node* n;
            E key;
            struct u* parent;
            u(node* n) : n(n), key(INT_MAX), parent(nullptr) {}
        };
        typedef struct u U;

    self MST_Prim(node* r) {
        // some code
        min_priority_queue::heapDecreaseKey(V, v, weight(u->n,v->n));
        // more code
        self MST;
        // and more code...
        return MST;
    }
};

// minpriorityqueue.h
template <typename G>
class MinPriorityQueue{
    private:
        typedef typename G::U U;
        typedef typename G::E E;
        typedef typename G::node node;
        static std::map<node*,int> positions;
    public:
        static void heapDecreaseKey(std::vector<std::pair<node*, U*> >& A, U* n, E key) {
            // implementation
        }
};

// minpriorityqueue.cpp
#include "minpriorityqueue.h"

template<typename G>
std::map<MinPriorityQueue<G>::node*,int> MinPriorityQueue<G>::positions = ;

I already tried defining positions without MinPriorityQueue<G>:: before node and it gives me another error. I also tried using typename MinPriorityQueue<G>:: and get the following:

Undefined symbols for architecture x86_64:
"MinPriorityQueue<Graph<Traits> >::positions", referenced from:

I've been trying to solve this problem for almost a day and couldn't find anything close to this.

Aucun commentaire:

Enregistrer un commentaire