
提示コードですがテンプレート関数を定義とヘッダーを分けたのですがエラーになりました。そもそもテンプレート関数はヘッダーとソースに定義と宣言を分けることは出来ないのでしょうか?
エラー [ 重大度レベル コード 説明 プロジェクト ファイル 行 抑制状態
エラー LNK2019 未解決の外部シンボル "int __cdecl test2<int>(int)" (??$test2@H@@YAHH@Z) が関数 _main で参照されました test C:\Users\yw325\Desktop\test\test\Main.obj 1
]
エラー[ 重大度レベル コード 説明 プロジェクト ファイル 行 抑制状態
エラー LNK1120 1 件の未解決の外部参照 test C:\Users\yw325\Desktop\test\Debug\test.exe 1
]
cpp
1#include <iostream> 2#include "test.hpp" 3 4 5//テンプレート関数 6template<typename t> 7t test(t a) 8{ 9 return a; 10} 11 12 13 14 15int main() 16{ 17 //int a = test<int>(3); 18 int a = test2<int>(3); 19 20 21 return 0; 22}
cpp
1#include "test.hpp" 2 3template<int> int test2(int a) 4{ 5 return a; 6}
hpp
1template<typename t> 2t test2(t a); 3 4template int test2(int a); 5 6 7

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。