5.C++新增了template以及STL 详见"12月2日——学习C++中STL,这篇就够了 - 董老师教育工作室的文章 - 知乎zhuanlan.zhihu.com/p/68" 6.C++新增了bool型变量和wchar_t型变量 #include<iostream.h> int main() { bool flag; flag = true; if(flag) cout << true << endl; return 0; } wchar_t是...
template 声明模板,实现泛型和参数化编程。 this this是一种实体,仅在类的非静态成员中使用,是指向类的对象的指针。 typedef 用以给数据类型取别名。 virtual 声明虚基类或虚函数。具有虚基类或虚函数的类是多态类(polymorphic class),需要运行时提供支持来判断成员函数调用分派到的具体类型。 typeid 返回指针或引用...
enum { Value = FSize::Value + FSize::Value }; }; template struct FSize{ // 需要带模板类型 enum { Value = sizeof(TLast) }; }; cout ::Value 借助std::integral_constant(value为值,value_type为值类型,type为自身)可方便地实现编译时计算: template struct MyFac:integral_constant::value>{};...
enum MyEnum : int { A, B, C, D }; template <typename _t> class MyTemplate { public: void print() { cout << "not using any specialisation" << endl; } }; template <> class MyTemplate <MyEnum> { public: void print() { cout ...
struct S1 { void f(int); void f(int, int); }; struct S2 { template <class C, void (C::*Function)(int) const> void f() {} }; void f() { S2 s2; s2.f<S1, &S1::f>(); } 当前编译器可以准确报告错误,因为模板参数类型不匹配模板参数(该参数是指向 const 成员的指针,但函数为...
enum EA{a,b,c};};template<> enum T1<int>::EA{e,f,d};int main(){ T1<char> s;int a...
1) C++98 的 enum是“非域内的”;而 C++11 的 enum class是“域内的”,限制了枚举成员只在域内可见 2) enum class 的缺省潜在类型 (underlying type) 是 int 型,而 enum 没有缺省潜在类型 3) enum class一般总是前置声明,而 enum 只有在指定了潜在类型时才可以是前置声明 参考资料 《Effective Modern ...
C/C++中常用的编程关键字 关键字 作用:关键字是C++中预先保留的单词(标识符)在定义变量或者常量时候,不要用关键字C++关键字如下:1. asm asm (指令字符串):允许在 C++ 程序中嵌入汇编代码。2. auto auto(自动,automatic)是存储类型标识符,表明变量"自动"具有本地范围,块范围的变量声明(如for循环体内...
Compiler warning (level 1) C4662explicit instantiation; template-class 'identifier1' has no definition from which to specialize 'identifier2' Compiler warning (level 1) C4667'function': cannot find a function template that matches the explicit instantiation ...
struct S1 { void f(int); void f(int, int); }; struct S2 { template <class C, void (C::*Function)(int) const> void f() {} }; void f() { S2 s2; s2.f<S1, &S1::f>(); } The current compiler correctly gives an error, because the template parameter type doesn't match...