LNK2019 unresolved external symbol - C++
.hpp
Код:
#pragma once
#include<future>
class threadpool
{
public:
threadpool(size_t threadCount);
virtual ~threadpool();
template<class F, class ...Args>
auto AddTask(F&& f, Args&&... args) ->
std::future<typename std::result_of<F(Args...)>::type>;
};
#include<future>
class threadpool
{
public:
threadpool(size_t threadCount);
virtual ~threadpool();
template<class F, class ...Args>
auto AddTask(F&& f, Args&&... args) ->
std::future<typename std::result_of<F(Args...)>::type>;
};
Код:
#include "threadpool.hpp"
threadpool::threadpool(size_t threadCount)
{
}
threadpool::~threadpool()
{
}
template<class F, class... Args>
auto threadpool::AddTask(F&& f, Args&&... args)
-> std::future<typename std::result_of<F(Args...)>::type>
{
return std::future<typename std::result_of<F(Args...)>::type>();
}
threadpool::threadpool(size_t threadCount)
{
}
threadpool::~threadpool()
{
}
template<class F, class... Args>
auto threadpool::AddTask(F&& f, Args&&... args)
-> std::future<typename std::result_of<F(Args...)>::type>
{
return std::future<typename std::result_of<F(Args...)>::type>();
}
Код:
#include <iostream>
#include "threadpool.hpp"
int foo(int i1, int i2)
{
std::cout << i1 + i2 << std::endl;
return i2 - i1;
}
template<class F, class ...Args>
auto add_task(F&& f, Args&&... args)
->std::future<typename std::result_of<F(Args...)>::type>
{
return std::future<typename std::result_of<F(Args...)>::type>();
}
int main()
{
threadpool th(4);
// Ошибка.
// auto res = th.AddTask(&foo, 12, 3);
// std::cout << res.get() << std::endl;
// Работает.
auto res2 = add_task(&foo, 12, 3);
std::cout << res2.get() << std::endl;
getc(stdin);
return 0;
}
#include "threadpool.hpp"
int foo(int i1, int i2)
{
std::cout << i1 + i2 << std::endl;
return i2 - i1;
}
template<class F, class ...Args>
auto add_task(F&& f, Args&&... args)
->std::future<typename std::result_of<F(Args...)>::type>
{
return std::future<typename std::result_of<F(Args...)>::type>();
}
int main()
{
threadpool th(4);
// Ошибка.
// auto res = th.AddTask(&foo, 12, 3);
// std::cout << res.get() << std::endl;
// Работает.
auto res2 = add_task(&foo, 12, 3);
std::cout << res2.get() << std::endl;
getc(stdin);
return 0;
}
1) Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "public: class std::future<int> __thiscall threadpool::AddTask<int (__cdecl*)(int,int),int,int>(int (__cdecl*&&)(int,int),int &&,int &&)" (??$AddTask@P6AHHH@ZHH@threadpool@@QAE?AV?$future@H@std@@$$QAP6AHHH@Z$$QAH1@Z) referenced in function _main thrpl2 D:Учёба3 курс1 семестр__TEMP__WinAPIthrpl2thrpl2Source.obj 1
2) Severity Code Description Project File Line Suppression State
Error LNK1120 1 unresolved externals thrpl2
Объясните причину этой ошибки и помогите её исправить пожалуйста.
PS: Всё более птичий, всё более хаскель...