C ++类

时间:2015-07-07 14:00:56

标签: c++ eclipse c++11 linker lnk2019

当我尝试构建项目时遇到以下链接器问题。

我已经看过这里的其他帖子,据我所知,我使用的唯一外部是标准成员(并用std::)或原语识别。有什么明显的东西我在这里不见了吗?

使用内部eclipse构建器在Win 7 professional 64bit上使用Eclipse C ++(Mars)构建。

日志:

  

link / debug / nologo /OUT:SAD-Snoop.exe“src \ ByteScanner.obj”“src \ EncType.obj”“src \ SAD-Snoop.obj”“src \ SearchHits.obj”

     

SearchHits.obj:错误LNK2019:未解析的外部符号“public:long __thiscall SearchHits :: GetHitAddress(unsigned int)”(GetHitAddress @ SearchHits @@ QAEJI @ Z)在函数“public:bool __thiscall SearchHits :: Merge”中引用class SearchHits)“(?Merge @ SearchHits @@ QAE_NV1 @@ Z)

     

SAD-Snoop.exe:致命错误LNK1120:1个未解析的外部

     

14:28:44构建完成(耗时909毫秒)

部首:

/*
 * SearchHits.h
 *
 *  Created on: 30 Jun 2015
 *      Author: Nick Boyd
 */

#ifndef SEARCHHITS_H_
#define SEARCHHITS_H_

#include <iostream>
#include <string>
#include <vector>

class SearchHits {
public:
    SearchHits();
    ~SearchHits();
    bool AddHit(std::string content, long address);
    unsigned int CountHits();
    std::string GetHit(unsigned int hitNumber);
    long GetHitAddress(unsigned int hitNumber);
    bool Merge(SearchHits hits);
private:
    std::vector<std::string> hits;
    std::vector<long> hitAddresses;
};

#endif /* SEARCHHITS_H_ */

类:

/*
 * SearchHits.cpp
 *
 *  Created on: 30 Jun 2015
 *      Author: Nick Boyd
 */

#include "SearchHits.h"
#include <string>
#include <iostream>
#include <vector>

std::vector<std::string> hitContents;
std::vector<long> hitAddresses;

SearchHits::SearchHits() {
}

SearchHits::~SearchHits() {
    hitContents.clear();
    hitAddresses.clear();
}

bool SearchHits::AddHit(std::string hitContent, long address) {
    hitContents.push_back(hitContent);
    hitAddresses.push_back(address);
    return ((hitContents.back() == hitContent)
            && (hitAddresses.back() == address));
}

unsigned int SearchHits::CountHits() {
    return hitContents.size();
}

std::string SearchHits::GetHit(unsigned int hitNumber) {
    if (hitNumber < hitContents.size()) {
        return hitContents[hitNumber];
    } else {
        std::cout << "Error in Function [SearchHits::GetHit()]" << std::endl
                << "Parameter [hitNumber] out of bounds: "
                << hitNumber + " Upper Limit: " << hitContents.size()
                << std::endl;
        throw new std::invalid_argument(
                "Error in Function [SearchHits::GetHit()] Parameter [hitNumber] out of bounds: "
                + std::to_string(hitNumber));
    }
}

long GetHitAddress(unsigned int hitNumber) {
    if (hitNumber < hitContents.size()) {
        return hitAddresses[hitNumber];
    } else {
        std::cout << "Error in Function [SearchHits::GetHitAddress()]"
                << std::endl << "Parameter [hitNumber] out of bounds: "
                << hitNumber << " Upper Limit: " << hitContents.size()
                << std::endl;
        throw new std::invalid_argument(
                "Error in Function [SearchHits::GetHitAddress()] Parameter [hitNumber] out of bounds: "
                + std::to_string(hitNumber));
    }
}

bool SearchHits::Merge(SearchHits hits) {
    bool overallResult = true;
    unsigned int i = 0;

    while ((i < hits.CountHits()) && overallResult) {
        bool tempResult = false;
        unsigned char attemptNum = 1;
        while ((tempResult == false) && (attemptNum++ <= 5)) {
            tempResult = this->AddHit(hits.GetHit(i),hits.GetHitAddress(i));
        }
        overallResult = (overallResult && tempResult);
        ++i;
    }
    if (overallResult) {
        hits.~SearchHits();
    }
    return overallResult;
}

1 个答案:

答案 0 :(得分:2)

更改

long GetHitAddress(unsigned int hitNumber)

long SearchHits::GetHitAddress(unsigned int hitNumber)