1.原始字符串字面量 R"(字符串)"
const char* str1 = "D:hello\world\test.txt";
const char* str2 = R"(D:hello\world\test.txt)";
std::cout << "直接输出str:\t\t" << str1 << std::endl;
std::cout << "原始字符串输出str:\t" << str2 << std::endl;
2.nullptr空指针、constexpr修饰常量、auto自动类型推导
//nullptr置空指针
int* a = nullptr;
//constexpr修饰常量,可以是数据类型、表达式、函数
constexpr int b = 10;
//b = 20;error
//auto自动数据类型
char c = 'c';//char
auto cc = 'c';//char
3.auto和decltype在模板的配合使用
template <typename T1,typename T2>
auto test03(T1 x, T2 y) -> decltype(x + y)
{
return x + y;
}
4.类继承,final的类方法不能重写其父类虚函数、override重写虚函数的检测
class Base
{
public:
virtual void print() {
std::cout << "这是父类" << std::endl;
}
};
class Child : public Base
{
public:
void print() override//override如果不存在print的虚函数会报错
{
std::cout << "这是儿子" << std::endl;
}
};
class GrandChild : public Child
{
void print() override final//final的类不能派生
{
std::cout << "这是孙子" << std::endl;
}
};
class GrandGrand : public GrandChild
{
//error,这里重写加了final的父类虚函数报错
//void print() override final//final的类不能派生
//{
// std::cout << "这是孙子的儿子" << std::endl;
//}
};
5.委托构造函数和继承构造函数
class A
{
public:
//链式委托
A(int a)
{
this->M_a = a;
}
A(int a,bool b) : A(a)
{
this->M_b = b;
}
A(int a,bool b,char c) : A(a,b)
{
this->M_c = c;
}
int M_a;
bool M_b;
char M_c;
};
class B : public A
{
//继承父类构造
using A::A;
};
B b1(5, true, '!');
std::cout << b1.M_a << " " << b1.M_b << " " <<b1.M_c << std::endl;
标签:std,cout,--,auto,C++,char,int,bool,C11
From: https://blog.51cto.com/u_16071993/7236207