以下のコードで:
マテリアル.h:
#ifndef MATERIA_H
#define MATERIA_H
class material
{
public:
template <class type>
static material* MakeMaterial(typename type::configtype, long);
template <class type>
void CreateNaturalForm(typename type::configtype, long);
…
};
template <class type>
material* material::MakeMaterial(typename type::configtype Config, long Volume)
{
return type::Spawn(Config, Volume);
}
#endif
マテリアル.h:
#ifndef MATERIAS_H
#define MATERIAS_H
#include "materia.h"
#include "confdef.h"
class solid : public material {
public:
typedef solidmaterial configtype;
…
};
template material* material::MakeMaterial<solid>(solidmaterial, long);
template <class type>
void material::CreateNaturalForm(typename type::configtype Config, long Volume)
{
…
MakeMaterial(Config, Volume); // Error here
…
}
template void material::CreateNaturalForm<solid>(solidmaterial, long);
#endif
confdef.h:
#ifndef CONFDEF_H
#define CONFDEF_H
enum solidmaterial {
WOOD,
…
};
#endif
main.cpp
#include "materia.h"
#include "materias.h"
#include "confdef.h"
int main()
{
material::MakeMaterial(WOOD, 500); // Same error here
}
(エラーを再現する上記のコードのオンライン バージョンは次のとおりです。)
コメント行に次のコンパイル エラー メッセージが表示されます。
「MakeMaterial」の呼び出しに一致する関数がありません
私は何を間違っていますか?明示的なインスタンス化により、コンパイラが正しい関数を認識できるようになるべきではありませんか?
明示的に記述すればコードはコンパイルされますが、ここでの要点は引数からMakeMaterial<solid>
推測することです。どうすればこれを達成できますか?type
Config