Pergunta

So it's one of these compiler errors where I just cannot figure out the source of the problem.

This is the class LocalQualityMeasure, header

#include <unordered_set>

#include "../clustering/Clustering.h"
#include "../graph/Graph.h"

namespace Project {

/**
 * Abstract base class for all local clustering quality measures.
 */
class LocalQualityMeasure {


public:

    LocalQualityMeasure();

    virtual ~LocalQualityMeasure();

    virtual double getQuality(std::unordered_set<node>& C, Graph& G) = 0;
};

} /* namespace Project */

and source:

#include "LocalQualityMeasure.h"

namespace Project {

LocalQualityMeasure::LocalQualityMeasure() {
}

LocalQualityMeasure::~LocalQualityMeasure() {
    // TODO Auto-generated destructor stub
}


} /* namespace Project */

And this is a derived class Conductance, header

#include <algorithm>

#include "LocalQualityMeasure.h"

namespace Project {

class Conductance: public Project::LocalQualityMeasure {
public:
    Conductance();
    virtual ~Conductance();

    virtual double getQuality(std::unordered_set<node>& C, Graph& G);
};

} /* namespace Project */

and source

#include "Conductance.h"

namespace Project {

Conductance::Conductance() : LocalQualityMeasure() {
}

Conductance::~Conductance() {
    // TODO Auto-generated destructor stub
}

double getQuality(std::unordered_set<node>& C, Graph& G) {

    double volume = 0;
    double boundary = 0;
    double all = 0;

    for (auto it = C.begin(); it != C.end(); ++it) {
        volume = volume + G.degree(*it);
        G.forNeighborsOf(*it, [&](node v){
            if (C.find(v) == C.end()) boundary++;
        });
    }

    G.forNodes([&](node v){
        all = all + G.degree(v);
    });

    if (volume == 0 || all-volume == 0)
        return 1;
    return boundary / std::min(volume, all-volume);
}

} /* namespace Project */

The linker complains about a missing vtable:

Undefined symbols for architecture x86_64:
  "Project::Conductance::getQuality(std::unordered_set<long long, std::hash<long long>, std::equal_to<long long>, std::allocator<long long> >&, Project::Graph&)", referenced from:
      vtable for Project::Conductance in Conductance.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
make: *** [Project-CommunityDetection-DPar] Error 1

I use GCC 4.7 with --std=c++11.

Foi útil?

Solução

You forgot the class scope in your implementation of getQuality:

double Conductance::getQuality(std::unordered_set<node>& C, Graph& G) 
{
  .....
}

Outras dicas

You need to add in your implementation file the class scope:

double Conductance::getQuality(std::unordered_set<node>& C, Graph& G) {...

Otherwise the linker is not able to find the implementation for the method defined in the header.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top