Files
912-notes/c++ note/common_bugs.md
2019-05-21 14:45:02 +08:00

13 lines
805 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
Some Common Bugs
================
为了更好的debug我觉得还是有必要把平时出现的有点难度的bug记录下来以让自己知道你自己写的究竟是些啥
> 在调用了构造函数,进行了必要的初始化,之后的操作却出现了空指针?
因为我嵌套调用了构造函数。在构造函数中调用其他构造函数,只会产生一个匿名的对象,并不会帮助你初始化当前的对象。
> 写了一个`read`函数,接受一个`istream`以及一个对象作为参数,即`read(istream is, myClass object)`。在函数体中利用输入流将数据读入对象中,并返回该`istream`作为进一步的判断或者使用。结果`object`没有得到赋值?!
因为我是个傻逼。传入的`object`肯定要是引用啊。