0

我正在尝试编写一个类,我终于可以编译它,但 Visual Studio 仍然显示存在错误(带有红线)。

问题出在(我在 Visual Studio 画红线的地方写了@problem here@):

1. const priority_queue<int,vector<int>,greater<int> @>@ * CM::getHeavyHitters() {
2.     return & @heavyHitters@ ;
3. }

它说:

  1. “错误:需要一个标识符”(在第一行)
  2. “错误:标识符“heavyHitters”未定义”(在第二行)

第一个问题我完全不明白。第二个我不明白,因为heavyHitters 是CM 的成员,我包括CM。

顺便说一句,我试图建立。它没有解决问题。

谢谢!!!

整个代码在这里:


Count-Min Sketch.cpp

#include "Count-Min Sketch.h"


CM::CM(double eps, double del) {

}

void CM::update(int i, int long unsigned c) {

}

int long unsigned CM::point(int i) {
    int min = count[0][calcHash(0,i)];

    return min;
}

const priority_queue<int,vector<int>,greater<int>>* CM::getHeavyHitters() {
    return &heavyHitters;
}

CM::CM(const CM &) {

}

CM::~CM() {

}


int CM::calcHash(int hashNum, int inpt) {
    int a = hashFunc[hashNum][0];
    int b = hashFunc[hashNum][1];
    return ((a*inpt+b) %p) %w;
}

bool CM::isPrime(int a) {
    bool boo = true;

    return boo;
}

int CM::gePrime(int n) {
    int ge = 2;

    return ge;
}

Count-Min Sketch.h

#pragma once

#ifndef _CM_H
#define _CM_H

using namespace std;
#include <queue>

class CM {
private:
    // d = ceiling(log(3,1/del)), w = ceiling(3/eps)
    int d,w,p; 
    // [d][w]
    int long unsigned *(*count); 
    // [d][2]
    int *(hashFunc[2]); 
    // initialized to 0. norm = sum(ci)
    int long unsigned norm; 
    // Min heap
    priority_queue<int,vector<int>,greater<int>> heavyHitters;

    // ((ax+b)mod p)mod w
    int calcHash(int hashNum, int inpt);
    // Is a a prime number
    bool isPrime(int a);
    // Find a prime >= n
    int gePrime(int n); 

public:
    // Constructor
    CM(double eps, double del);
    // count[j,hj(i)]+=c for 0<=j<d, norm+=c, heap update & check
    void update(int i, int long unsigned c);
    // Point query ai = minjcount[j,hj(i)]
    int long unsigned point(int i); 
    const priority_queue<int,vector<int>,greater<int>>* getHeavyHitters();
    // Copy constructor
    CM(const CM &);
    // Destructor
    ~CM();
};

#endif // _CM_H
4

1 回答 1

1

>> is a single token, the right-shift (or extraction) operator. Some compilers don't recognize it correctly in nested template specialization. You have to put a space between the two angle brackets like this:

Type<specType<nestedSpecType> > ident;
                            ^^^
于 2013-06-15T19:52:34.580 回答