Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/154.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 在静态库中使用OutputIterator时发生链接器错误_C++_Linker_Lnk2019 - Fatal编程技术网

C++ 在静态库中使用OutputIterator时发生链接器错误

C++ 在静态库中使用OutputIterator时发生链接器错误,c++,linker,lnk2019,C++,Linker,Lnk2019,我试图寻找类似的问题,但没有找到一个线程可以帮助我解决我的问题。如果我错过了,请提前道歉 我对C++非常陌生,即使我有其他语言如java的经验,我也使用VisualStudio Express 2015。 所以,我有一个类,它执行一些集合计算。使用输出迭代器的想法来源于此,我从中复制了代码的结构 标题如下所示: #pragma once #include <tuple> #include <vector> #include <iterator> using

我试图寻找类似的问题,但没有找到一个线程可以帮助我解决我的问题。如果我错过了,请提前道歉

<>我对C++非常陌生,即使我有其他语言如java的经验,我也使用VisualStudio Express 2015。 所以,我有一个类,它执行一些集合计算。使用输出迭代器的想法来源于此,我从中复制了代码的结构

标题如下所示:

#pragma once
#include <tuple>
#include <vector>
#include <iterator>

using namespace std;

class SomeComputation
{
public:
    SomeComputation(void);
    ~SomeComputation(void);


    template <typename Range1, typename Range2, typename Range3, typename OutputIterator>
    void compute(Range1 const & r1, Range2 const &r2, Range3 const & r3, OutputIterator out);
};
#include "SomeComputation.h"
using namespace std;

SomeComputation::SomeComputation(void)
{
// build the object
}

SomeComputation::~SomeComputation(void)
{
// destroy it
}
template <typename Range1, typename Range2, typename Range3, typename OutputIterator>
void SomeComputation::compute(Range1 const & r1, Range2 const &r2, Range3 const & r3, OutputIterator out) {

// do some set computation here
// then save the result using the output iterator
*out++ = std::make_tuple([OMISSIS]);
}
#pragma一次
#包括
#包括
#包括
使用名称空间std;
类计算
{
公众:
某些计算(无效);
~z~计算(无效);
模板
无效计算(范围1常量和r1,范围2常量和r2,范围3常量和r3,输出计数器输出);
};
实现如下所示:

#pragma once
#include <tuple>
#include <vector>
#include <iterator>

using namespace std;

class SomeComputation
{
public:
    SomeComputation(void);
    ~SomeComputation(void);


    template <typename Range1, typename Range2, typename Range3, typename OutputIterator>
    void compute(Range1 const & r1, Range2 const &r2, Range3 const & r3, OutputIterator out);
};
#include "SomeComputation.h"
using namespace std;

SomeComputation::SomeComputation(void)
{
// build the object
}

SomeComputation::~SomeComputation(void)
{
// destroy it
}
template <typename Range1, typename Range2, typename Range3, typename OutputIterator>
void SomeComputation::compute(Range1 const & r1, Range2 const &r2, Range3 const & r3, OutputIterator out) {

// do some set computation here
// then save the result using the output iterator
*out++ = std::make_tuple([OMISSIS]);
}
#包括“SomeComputation.h”
使用名称空间std;
SomeCalculation::SomeCalculation(void)
{
//构建对象
}
SomeCalculation::~SomeCalculation(void)
{
//摧毁它
}
模板
void SomeComputation::compute(范围1常量&r1,范围2常量&r2,范围3常量&r3,输出计算器输出){
//在这里做一些集合计算
//然后使用输出迭代器保存结果
*out++=std::make_tuple([OMISSIS]);
}
现在,该类打包在一个静态库中,该库正确链接到另一个项目,我这样称呼它:

#include <vector>
#include <tuple>
#include <iterator>
#include <SomeComputation.h>

using namespace std;
    void MyClass::myFunction(){
    // init data (please assume that 
    //minQ1, maxQ1, etc. are double vars correctly initialized)
        vector<double> rQ0q1;
        rQ0q1.push_back(minQ1);
        rQ0q1.push_back(maxQ1);
        vector<double> rQ0q2;
        rQ0q2.push_back(minQ2);
        rQ0q2.push_back(maxQ2);
        vector<double> rQ0r3;
        rQ0r3.push_back(minR3);
        rQ0r3.push_back(maxR3);
        SomeComputation s = SomeComputation();
        vector<tuple<double, double, double>> result;
        s.compute(rQ0q1, rQ0q2, rQ0r3, std::back_inserter(result));
    }
#包括
#包括
#包括
#包括
使用名称空间std;
void MyClass::myFunction(){
//初始化数据(请假设
//minQ1、maxQ1等是正确初始化的双变量)
矢量rQ0q1;
rQ0q1.向后推_(minQ1);
rQ0q1.向后推_(maxQ1);
矢量rQ0q2;
rQ0q2.向后推_(minQ2);
rQ0q2.向后推_(maxQ2);
向量rQ0r3;
rQ0r3.向后推_(minR3);
rQ0r3.向后推_(maxR3);
SomeComputation s=SomeComputation();
矢量结果;
s、 计算(rQ0q1、rQ0q2、rQ0r3、std::back_插入器(结果));
}
但是,我得到以下链接器错误LNK2019:

Error   LNK2019 unresolved external symbol "public: void __thiscall SomeComputation::compute<class std::vector<double,class std::allocator<double> >,class std::vector<double,class std::allocator<double> >,class std::vector<double,class std::allocator<double> >,class std::back_insert_iterator<class std::vector<class std::tuple<double,double,double>,class std::allocator<class std::tuple<double,double,double> > > > >(class std::vector<double,class std::allocator<double> > const &,class std::vector<double,class std::allocator<double> > const &,class std::vector<double,class std::allocator<double> > const &,class std::back_insert_iterator<class std::vector<class std::tuple<double,double,double>,class std::allocator<class std::tuple<double,double,double> > > >)" (??$compute@V?$vector@NV?$allocator@N@std@@@std@@V12@V12@V?$back_insert_iterator@V?$vector@V?$tuple@NNN@std@@V?$allocator@V?$tuple@NNN@std@@@2@@std@@@2@@SomeComputation@@QAEXABV?$vector@NV?$allocator@N@std@@@std@@00V?$back_insert_iterator@V?$vector@V?$tuple@NNN@std@@V?$allocator@V?$tuple@NNN@std@@@2@@std@@@2@@Z) referenced in function "public: void __thiscall ModelData::addDataAtFrame(int,class Vector,class Vector)" (?addDataAtFrame@ModelData@@QAEXHVVector@@0@Z)   [path and project name omitted] 1
错误LNK2019未解析的外部符号“public:void\u thiscall SomeComputation::compute(类std::vector const&,类std::vector const&,类std::vector const&,类std::back\u insert\u迭代器)”(??$compute@V?$vector@NV?$allocator@N@std@@@std@@V12@V12@V?$back\u插入_iterator@V?$vector@V?$tuple@NNN@性病病毒$allocator@V?$tuple@NNN@std@@@2@@@std@@@2@@@SomeComputation@@@QAEXABV$vector@NV?$allocator@N@std@@@std@@00V?$back\U插入_iterator@V?$vector@V?$tuple@NNN@性病病毒$allocator@V?$tuple@NNN@std@@@2@@std@@@2@@Z)在函数中引用“public:void\uu thiscall ModelData::addDataAtFrame(int,类向量,类向量)”(?addDataAtFrame@ModelData@@QaexVvector@@0@Z)[省略路径和项目名称]1
现在,虽然我可以通过使用“更传统的“返回值,我不明白是什么导致了它以及它为什么会发生。我说库是正确链接的,因为我可以毫无问题地使用库的所有其他函数/对象/类,但是如果我使用这个函数/对象/类,我会出错。有人能帮我澄清一下吗?”


非常感谢。

在头文件而不是源文件中定义模板函数:


我们都在这一点上,在这一行:
s.compute(rQ0q1,rQ0q2,rQ0r3,std::back_inserter(result);
结尾缺少一个
,但这可能来自复制是的,这是一个来自复制的错误。谢谢你指出这一点,我将编辑这个问题。