C++
echo_xiao9
这个作者很懒,什么都没留下…
展开
-
[C++]友元函数、友元类 friend
友元函数When the function is declared as a friend, then it can access the private and protected data members of the class.#include <iostream>#include <string>using namespace std;class sample{ int length, breadth; public: sample(int翻译 2020-11-02 20:44:16 · 140 阅读 · 0 评论 -
[C] assert() 函数的用法
C Language: assert macro(Assert Truth of Expression)In the C Programming Language, assert is a macro that is designed to be used like a function. It checks the value of an expression that we expect to be true under normal circumstances.If expression is翻译 2020-10-27 21:50:51 · 175 阅读 · 0 评论 -
error: Undefined symbols for architecture x86_64 Qt
原因:1.没有包括需要的头文件2…h中的函数没有实现(构造函数特别容易漏掉)参考:https://blog.csdn.net/gongziwushuang/article/details/95453477原创 2020-10-20 22:06:57 · 439 阅读 · 0 评论 -
[C++]cannot jump from switch statement to this case label
switch (i) { case 1: disk d = tower1.pop(); break; case 2: disk d = tower2.pop(); break; case 3: disk d = tower2.pop(); break; }在SEP lab3 中,switch报错cannot jump from switch statement to this case l..原创 2020-10-20 15:44:36 · 7563 阅读 · 2 评论 -
【C++】stringstreams使用
stringstreams使用说明使用stringstream需要包括头文件#include 继承关系注1:使用stringstream进行类型匹配。#include <iostream> #include <sstream> using namespace std; int main() { stringstream str; str.str("1 56.7"); //上述两个过程可以简单写..原创 2020-10-11 22:05:51 · 526 阅读 · 0 评论 -
【C++】substr()
substr有2种用法:假设:string s = “0123456789”;string sub1 = s.substr(5); //只有一个数字5表示从下标为5开始一直到结尾:sub1 = “56789”string sub2 = s.substr(5, 3); //从下标为5开始截取长度为3位:sub2 = “567”...原创 2020-09-30 14:47:40 · 476 阅读 · 0 评论 -
【C++】转二进制,位运算
#include <iostream>using namespace std;void BinaryRecursion(int n){ int a; a = n % 2; // 取余 n = n >> 1; //右移一位 相当于除以2 if(0 != n) { BinaryRecursion(n); } cout<<a;}int main(int argc, char *argv[])原创 2020-09-23 22:07:49 · 657 阅读 · 0 评论 -
【C++】多态、virtual 函数、指针数组
//shape.cpp//忽略其他函数class shape{private:public: virtual double area()=0;}class rectangle:public shape{public: virtual double area(){ return 1; }}class rectangle:public shape{private: double x; double y;public: virtual double area(){ r原创 2020-09-23 21:40:33 · 143 阅读 · 0 评论 -
【C++】函数返回对象为引用
当返回类型为引用时,我们可以用引用来接受,也可以用普通变量来接受。返回类型为普通类型时,例如int,被调函数结束的时候,会生成一个临时对象,然后return的内容拷贝给这个临时对象。但返回类型为引用时,不会生成临时对象。会直接返回对象。在写Lab1,给StudentWapper赋值的时候,赋值不进去,debug 发现赋值的是一个临时对象。要传入引用才行//main.cppStudentWrapper &sw = cl->getStudentWrapper(id);//正确Stu.原创 2020-09-23 18:56:30 · 921 阅读 · 0 评论