【问题标题】:Unexpected LNK 2019 in C++ classC++ 类中的意外 LNK 2019
【发布时间】:2015-09-25 01:39:21
【问题描述】:

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

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

使用内部 Eclipse 构建器在 Win 7 Professional 64 位上使用 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(类 SearchHits)" (?Merge@SearchHits@@QAE_NV1@@Z)

SAD-Snoop.exe : 致命错误 LNK1120: 1 unresolved externals

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;
}

【问题讨论】:

  • SearchHits::GetHitAddress 您在定义中缺少类范围。

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


【解决方案1】:

改变

long GetHitAddress(unsigned int hitNumber)

long SearchHits::GetHitAddress(unsigned int hitNumber)

【讨论】:

  • 谢谢,毕竟这是显而易见的事情。 (从 Java、PHP 和 AS3 转换)
猜你喜欢
  • 2014-05-13
  • 2013-05-02
  • 1970-01-01
  • 1970-01-01
  • 2018-11-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多