我有一个类可以在窗口中移动、着色、设置文本等任何 GUI:
class BasicOption
{
public :
template <class T>
void SetPosition ( float x , float y , T const*Obj);
};
然后像这样定义函数:
template <class T>
void BasicOption::SetPosition ( float x , float y , T const*Obj)
{
this->Obj->SetPosition(x ,y );
}
我有创建这样一个窗口的类
class GUI_Window : public BasicOption
{
public: // <-- This colon was added in response to some answers
GUI_Window(float const&width , float const&height String const&name)
};
好的,一切正常,但如果我在主函数中调用 SetPosition,我会得到 p>
error: LNK2019 unresolved external symbol "public"
主要.cpp
GUI_Window *W ; // MyWindow
int WINAPI wWinMain ( HINSTANCE hInst , HINSTANCE hPrev , LPWSTR lmcmdline , int nShowCmd )
{
..............
...........
..........
...........
W->SetPosition ( 520 , 250 , W );
}
我也这样修改代码
{
W->SetPosition <GUI_Window>( 520 , 250 , W );
}
还是有同样的问题
/**/
我发现问题了
这是链接,我在 main.cpp 中定义了函数并且它工作正常 但如果我在 main.cpp 文件之外定义它,我会收到错误信息,请提供任何帮助链接此功能 并在 main.cpp 之外定义它
最佳答案
它是 public:
而不是 public
- 你少了一个分号。
class GUI_Window : public BasicOption
{
public:
GUI_Window(float const&width , float const&height String const&name);
};
关于c++ - 错误 : LNK2019 unresolved external symbol "public" in template Function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5926650/