C + +未解决的外部符号

时间:2018-06-27 23:35:08

标签: c++ templates vector

我正在编写一个简单的代码,尝试使用模板读取2D向量。但出现类似以下错误:

严重性代码描述项目文件行抑制 StateError LNK2019无法解析的外部符号

我的main.cpp就像:

/* Undefined behavior when a non-alpha-num substring parameter is used. */
bool find_alphanum_string_CI(const std::wstring& baseString, const std::wstring& subString)
{
    /* Fail fast if the base string was smaller than what we're looking for */
    if (subString.length() > baseString.length()) 
        return false;

    auto it = std::search(
        baseString.begin(), baseString.end(), subString.begin(), subString.end(),
        [](char ch1, char ch2)
        {
            return std::toupper(ch1) == std::toupper(ch2);
        }
    );

    if(it == baseString.end())
        return false;

    size_t match_start_offset = it - baseString.begin();

    std::wstring match_start = baseString.substr(match_start_offset, std::wstring::npos);

    /* Typical special characters and whitespace to split the substring up. */
    size_t match_end_pos = match_start.find_first_of(L" ,<.>;:/?\'\"[{]}=+-_)(*&^%$#@!~`");

    /* Pass fast if the remainder of the base string where
       the match started is the same length as the substring. */
    if (match_end_pos == std::wstring::npos && match_start.length() == subString.length()) 
        return true;

    std::wstring extracted_match = match_start.substr(0, match_end_pos);

    return (extracted_match.length() == subString.length());
}

我的read_2d.h文件是:

#include "header\\read_2d.h"
#include <iostream>  
#include <fstream>
#include <vector>
#include <string>
#include <stdlib.h>
using namespace std;

int main()
{
    //input image array parameters and initialize a 2D array
    int nx = 200;
    int ny = 200;
    std::vector<std::vector<unsigned char> > image(nx, std::vector<unsigned char>(ny));
    std::vector<std::vector<unsigned char> > mask(nx, std::vector<unsigned char>(ny));
    string disk_filename = "disk.dat";

    //read image
    read_2d<unsigned char>(disk_filename, image);

    return 0;

}

我的read_2d.cpp是:

#ifndef READ_2D_H    // To make sure you don't declare the function more than once by including the header multiple times.
#define READ_2D_H


#include <iostream>  
#include <fstream>
#include <vector>
#include <string>
using namespace std;

template <typename myType>
void read_2d(string filename, vector< vector<myType> >& image);

#endif

有人可以帮助我指出我做错了什么吗?任何评论将不胜感激!

0 个答案:

没有答案