0voice / cpp_new_features Goto Github PK
View Code? Open in Web Editor NEW2021年最新整理, C++ 学习资料,含C++ 11 / 14 / 17 / 20 / 23 新特性、入门教程、推荐书籍、优质文章、学习笔记、教学视频等
2021年最新整理, C++ 学习资料,含C++ 11 / 14 / 17 / 20 / 23 新特性、入门教程、推荐书籍、优质文章、学习笔记、教学视频等
`int main() {
int a = 10;
int b = 20;
swap1(a, b); // 值传递不会改变实参
swap2(&a, &b); //地址传递会改变实参
cout << "a = " << a << endl;
cout << "b = " << b << endl;
system("pause");
return 0;
}修改成这样子会不会更好点呢?
int main() {
int a = 10;
int b = 20;
swap1(a, b); // 值传递不会改变实参
cout << "swap1 a = " << a << endl;
cout << "swap1 b = " << b << endl;
swap2(&a, &b); //地址传递会改变实参
cout << "swap2 a = " << a << endl;
cout << "swap2 b = " << b << endl;
system("pause");
return 0;
}`
图片打不开了
在 ”C++11常用新特性(二)“ 章节中,说道:
`class Filter
{
public:
Filter(int divisorVal):
divisor{divisorVal}
{}
std::function<bool(int)> getFilter()
{
return [=](int value) {return value % divisor == 0; };
}
private:
int divisor;
};`
这个类中有一个成员方法,可以返回一个lambda表达式,这个表达式使用了类的数据成员divisor。而且采用默认值方式捕捉所有变量。你可能认为这个lambda表达式也捕捉了divisor的一份副本,但是实际上并没有。因为数据成员divisor对lambda表达式并不可见,你可以用下面的代码验证:*******.
我验证过了, [=] 能捕获到 类数据成员,比如下面没问题:
`#include
#include
using namespace std;
class Demo {
public:
Demo():m_i(100) {}
virtual ~Demo() {}
void func(int x) {
auto f1 = [=]{ std::cout << &m_i << std::endl; return m_i + x; };
std::cout << f1() << std::endl;
std::cout << &m_i << std::endl;
}
std::function<int(int)> getFunc() {
return [=](int val) { return val + m_i; };
}
void setData(int d) {
m_i = d;
}
private:
int m_i;
};
int main() {
Demo d;
d.func(10);
std::function<int(int)> ff;
{
Demo dd;
ff = dd.getFunc();
dd.setData(400);
}
std::cout << "-------" << std::endl;
//
std::cout << ff(200) << std::endl;
return 0;
}`
初级课程里面介绍 long int 是8字节,实际应该是 4字节
md里的“ACE : C++面向对象网络变成工具包”
是不是指 “编程工具包”?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.