作者yshihyu (yshihyu)
看板C_and_CPP
标题[问题] 静态函数呼叫非静态函数
时间Wed Sep 26 22:38:34 2018
开发平台(Platform): (Ex: Win10, Linux, ...)
Linux
编译器(Ex: GCC, clang, VC++...)+目标环境(跟开发平台不同的话需列出)
g++ 7.3.0
记得以前这样能编译过 , 是因为新版编译器问题嘛?
想在建构函数把this指标 assign 到 static 变数存放instance
https://gist.github.com/shihyu/9ef5b9a30e5221350fc1cbde00205627
可是现在无法编译过, 想请问一下这是什麽原因?
谢谢
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 106.104.121.78
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/C_and_CPP/M.1537972718.A.FD8.html
1F:→ thefattiger: A跟main之间加一行 09/26 23:23
2F:→ thefattiger: A* A::m_gA = nullptr; 09/26 23:23
3F:→ thefattiger: 宣告之後还要定义才不会link error 09/26 23:24
4F:→ yshihyu: 可以了感谢~ 在请教一下m_staticA 为什麽不需要定义 09/26 23:41
5F:→ yshihyu: 也能正常编译过? 但是static A* m_gA; 必须要定义? 09/26 23:42
6F:推 thefattiger: 因为你没用到,有用到的话也是会link error 09/26 23:47
7F:→ yshihyu: 了解 感谢 09/27 00:05
8F:→ tinlans: 要练习看错误讯息跟了解错误讯息 09/28 13:34