It might be a stupid question but I totally don't have any idea about the prompt.
The code is in a .cpp file
template <typename T> void foo2(T){}
template void foo2<int>(int);
VS2017 keeps telling me that: Function definition for function 'foo2' is not found. However, the code actually works in VS2017, no error message if I run it. I don't know if it is an IDE-specific problem or it is the code problem. As it is quite annoying, does anyone know why the prompt appears and how to fix it? Thanks!
=========Update===========
Here is the full code(Move the instantiation to .h file but still have the same problem):
test.h
#pragma once
template <typename T> void foo2(T);
template void foo2<int>(int);
test.cpp
#include "test.h"
#include "stdafx.h"
template <typename T>void foo2(T){}
main file
#include "stdafx.h"
#include "test.h"
int main()
{
int a = 1;
foo2(a);
}
I tend to believe that an IDE-specific question. If I ask VS to show the potential fix, it will create the following code in .cpp file:
template void foo2(int)
{
return template void();
}
which is definitely wrong. Even cannot pass the compilation.