![](https://img-blog.csdnimg.cn/20201014180756930.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
错误总结
一些易犯的错误
weixin_46060711
c/c++
展开
-
在类模板中,利用友元函数重载输出运算符 << 时,不加命名空间std会报错,不加 <T> 也会报错
类的头文件:Vector0.h#pragma once#include <iostream>//using namespace std;template <typename T>class Vector0{ public: Vector0(int size = 0); Vector0(const Vector0<T> &other); ~Vector0(void); Vector0& operator=(const Vect原创 2022-05-04 02:39:36 · 431 阅读 · 0 评论 -
关于赋值运算符“=”的重载问题
赋值运算符的重载,应该使用这种方式:Boy& operator=(const Boy &boy);注意:参数要使用引用!完整代码为:Boy类(所在文件:“Boy.h”):#include <string>using namespace std;class Boy{public: Boy(const char *name = NULL); ~Boy(); Boy& operator=(const Boy& boy); string g原创 2022-04-23 04:47:19 · 530 阅读 · 0 评论 -
如何删除vector中的特定的某一个成员
代码:#include <vector>int main(void) { vector<int> arry; arry.push.back(1); arry.push.back(2); arry.push.back(3); arry.push.back(4); return 0;}如何删除arry中值为3的成员?代码实现为:#include <vector>int main(void) { vector<int> a原创 2022-02-08 23:42:54 · 453 阅读 · 0 评论 -
关于auto的自动推导的使用
举个例子:auto x = 100;auto y = 3.14;相当于:int x = 100;double y = 3.14;原创 2022-02-08 22:11:26 · 199 阅读 · 0 评论 -
关于《error: 函数“int main(void)”已有主体》的错误
编译器:VC++2010#include <iostream>#include <string>#include <Windows.h>using namespace std;//定义“人类”class Human {public: //公有的, 公共的 void eat(); //类里面的方法,又称为成员函数 void sleep(); void work(); void play(); string getName(); int get原创 2021-12-30 15:35:16 · 4508 阅读 · 4 评论 -
输入数据时,前面的数据输入错误,导致后面的数据都不能输入。及解决这个问题的办法:cin.clear()和cin.sync()
一,输入数据时,前面的数据输入错误,导致后面的数据都不能输入#include <iostream>#include <Windows.h>#include <string>int main(void) { int a; int b; int c; std::cin >> a >> b >> c; std::cout << "a=" << a << std::endl; std原创 2021-12-13 02:03:46 · 836 阅读 · 0 评论 -
变量名错误;变量还没有定义,就直接使用;变量的输入与使用顺序不当;数据输入时,数据的类型不匹配
1.变量名错误1)变量名不能使用关键字int char; //编译失败2)变量名不能和函数名同名int system; //会导致后面不能使用system函数2.变量还没有定义,就直接使用age = 20;//变量一定要先定义,再使用。变量一定要先定义,再使用!3.变量的输入与使用顺序不当#include<iostream>#include<Windows.h>using namespace std;int main(void){ int原创 2021-12-13 00:55:03 · 1611 阅读 · 1 评论