我想在接口中使用static 方法提供单件,大概错误的原因知道了,想问下这种方式可行么?????

unhappyless 2014-09-28 08:10:42


class ITest
{
public:
static ITest* GetTest();
};

class Test : public ITest
{
public:
static ITest* GetTest()
{
static Test this_test;
return &this_test;
}
private:
Test(){}
};

int main()
{
ITest::GetTest();
}



========================================

1>正在编译...
1>Mian.cpp
1>正在链接...
1>Mian.obj : error LNK2019: 无法解析的外部符号 "public: static class ITest * __cdecl ITest::GetTest(void)" (?GetTest@ITest@@SAPAV1@XZ),该符号在函数 _main 中被引用
...全文
92 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
真相重于对错 2014-09-28
  • 打赏
  • 举报
回复
static 函数不能override
勤奋的小游侠 2014-09-28
  • 打赏
  • 举报
回复
1你定义一个接口类,又不是虚函数,简直是多此一举。 2单件应该将构造函数定义为私有才可以

64,685

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧