CC++易错小问题记录

xiaoxiao2021-03-01  16

1、若声明了重构函数(析构函数),而不去实现它,则编译类时可以通过,但在主函数中使用该类则编译器会报错:

unresolved external symbol "public: __thiscall..............

2、类的设计(以设计yyy类为例)

(1)xxx.h

#ifndef XXX_H_ #define XXX_H_ class yyy{ //---------- }; #endif

(2)xxx.cpp

#include <iostream> #include "xxx.h" //类实现 ‘

(3)usexxx.c

#include <iostream> #include "xxx.h" int main() { return 0; }

3、若在成员函数声明时将形参赋初值,则使用这个成员函数时可以不传递参数

4、继承是不显式申明为public继承,则不能使用基类中的方法

#include <iostream> class cls1 { public: cls1() { std::cout<<"cls1"<<std::endl; } void show() { std::cout<<"show1"<<std::endl; } }; class cls2:public cls1 { public: cls2() { std::cout<<"cls2"<<std::endl; } void show2() { std::cout<<"cls2 show2"<<std::endl; } }; int main() { cls2 obj; obj.show();//若cls2继承cls1不声明为public,该句不能编译通过 return 0; }

5、自动变量 凡是在函数内部的局部变量,都是自动变量(注意与百度百科里说的不一样) each local variable in a function comes into existence only when the function is called, and disappears when the function is exited. This is why such variables are usually known as automatic variables. "The C Programming Language"

6,指针与数组间不一般的关系: Any operation that can be achieved by array subscripting can also be done with pointers.

它们只有一个区别:指针是变量,数组名不是变量(a++就错了)

7,关于EOF

EOF的值是 0xffffffff

ctrl+d(linux)。注意,在我的ubuntu下,要按两次ctrl+d,而不是一次enter一次ctrl+d(虽然也能结束程序,但并不代表EOF) ctrl+z(windows) 因为linux下ctrl+z会出发信号SIGSTOP

转载请注明原文地址: https://www.6miu.com/read-3212553.html

最新回复(0)