auto

incomplete class usage with auto in template class

◇◆丶佛笑我妖孽 提交于 2019-12-10 02:54:15
问题 Is the following code well formed ? class B; template<class T> class A { B do_f() const; friend auto f(A const& a) {return a.do_f();} // #1 }; class B{}; template <class T> B A<T>::do_f() const { return B{};} int main() { A<double> a; f(a); } If I change auto in #1 by B , I got incomplete type error message. Compile with auto for gcc/clang Demo Fail with B Demo 回答1: [dcl.fct.def.general]/2: The type of a parameter or the return type for a function definition shall not be an incomplete or

rpm包安装java jar开机自启

可紊 提交于 2019-12-09 19:57:56
1.安装jdk; rpm -ivh jdk-8u201-linux-x64.rpm 2.配置jdk路径 打开/etc/profile 增加以下内容: export JAVA_HOME=/usr/java/jdk1.8.0_201 export JAVA_BIN=/usr/java/jdk1.8.0_201/bin export PATH=$PATH:$JAVA_HOME/bin export CLASSPATH=:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar export JAVA_HOME JAVA_BIN PATH CLASSPATH 3.更新配置 source /etc/profile 4.编写启动 脚本 启动脚本:start.sh #!/bin/sh nohup java -jar /home/test/auto-test.jar >test.log 2>&1& echo $! > /home/test/test.pid 停止脚本:stop.sh #!/bin/sh PID=$(cat /home/test/test.pid) kill -9 $PID 授予脚本权限 chmod +x start.sh chmod +x stop.sh 5.编写服务脚本 vim /usr/lib/systemd/system/autotest

GCC's decltype(auto) doesn't conform to the standard?

半城伤御伤魂 提交于 2019-12-09 16:28:27
问题 I tried compiling this C++ code under GCC 8.2 with different options and it always succeeds, produces no warnings and outputs true : int && a = 123; decltype(auto) b = a; std::cout << std::boolalpha << std::is_same<decltype(b), int&>::value; Meanwhile, the same code will not compile in Clang, and if my understanding of the standard is correct, that's the standard-conforming behavior. cppreference on decltype : If the argument is an unparenthesized id-expression or an unparenthesized class

STL标准库-容器-forward_list

北战南征 提交于 2019-12-09 13:00:38
技术在于交流、沟通,本文为博主原创文章转载请注明出处并保持作品的完整性。 forward_list即单向list,功能少额外开销就小.而且只能在前段插入元素 结构如下 一 定义 #include <forward_list> int main(int argc, const char * argv[]) { //a.定义 list<typeName> name; forward_list<int> l; //b.拷贝构造 forward_list<int> l1(l); //c.拷贝赋值 l1 = l; //d.按指定元素个数定义 含五个默认值是0的元素的链表 forward_list<int> l2(5); //e.指定元素个数及类型 含有5个值为2的链表 forward_list<int> l3(5,2); //f.指定赋值区域 forward_list<int> l4(l1.begin(),l1.end()); for(auto i : l) { cout<< i << endl; } return 0; } 二 与迭代器的使用 由于forward_list的迭代器内指向内存不连续 顾不能做迭代器 "+", "-" 操作 int main() { forward_list<int> l = {1,2,3,4,5,6,7,8,9,10}; //返回迭代器开始之前的位置 l

vmware12无法打开内核设备“\\\\.\\Global\\vmx86”

北城余情 提交于 2019-12-09 11:21:39
vmware12 无法打开内核设备“\\.\Global\vmx86”: 系统找不到指定的文件。你想要在安装 VMware Workstation 前重启吗? 打开vmware12后出现内核错误,查了一下,在自己的win10下面应该是如下的解决方法: 1. 找到c:\windows\system32\cmd.exe 文件,右击选择以管理员身份运行 2. 输入以下的命令并回车 net start vmci net start vmx86 net start VMnetuserif 3. 改变vmware几种服务的启动方式为: sc config vmci start= auto sc config vmx86 start= auto sc config VMnetuserif start= auto 这一点儿与win7下面的有所不同,特此提醒,win7下面的是: sc config vmci=auto sc config vmx86=auto sc config VMnetuserif=auto 如果无法运行命令,则从 VMware Workstation安装目录,找到 :vmci.sys文件并复制到c:\windows\system32\drivers 来源: https://www.cnblogs.com/chengjiaming/p/5092562.html

Any advantage of using the s suffix in C++ [duplicate]

假如想象 提交于 2019-12-08 16:04:41
问题 This question already has answers here : Advantages of using user-defined literal for strings instead of string literal (4 answers) Closed last year . My question is related to the use of the "s" suffix in C++? Example of code using the "s" suffix: auto hello = "Hello!"s; // a std::string The same could be written as: auto hello = std::string{"Hello!"}; I was able to find online that the "s" suffix should be used to minimizes mistakes and to clarify our intentions in the code. Therefore, is

C++14学习笔记(1)——泛型Lambda

五迷三道 提交于 2019-12-08 07:59:17
经过4个月的努力,终于把《C++ Primer》的第5版看完了,第5版增加了C++11的内容。个人喜欢追随新东西,因此下一步学习目标新标准C++14。 我将发表一系列C++14的学习笔记,欢迎大家指出错误。 在看《C++ Primer》的过程中我就是用VC2015来运行代码的,经过我的亲自试验,VC2015对C++11的支持是很好的, 至少《C++ Primer》中提到的特性全部都支持 。因此我将继续用VC2015学习C++14,看看它对C++14支持到什么程度。 泛型Lambda C++11中引入了Lambda表达式,但是必须将形式参数声明为具体的类型。而在C++14中,我们可以使用auto作为形式参数的类型说明: //代码1.1 auto lam = [](auto x, auto y) { return x + y; }; 当我们使用Lambda表达式时,编译器会自动推导参数和返回值类型: //代码1.2 auto a = lam(3, 4); //a为int auto b = lam(4.8, 9.5); //b为double 有没有觉得这特别像函数模板吗?实际上,编译器就是用函数模板的推导规则来进行推导的,因此代码1.1大致相当于: //代码1.3 struct { template<typename T1, typename T2> auto operator()

c++11——lambda表达式

半城伤御伤魂 提交于 2019-12-08 07:58:59
lambda表达式 函数式编程的一个语法,有如下优点: (1)声明式编程风格:就地匿名定义目标函数或函数对象,不需要额外写一个命名函数或者函数对象。以更直接的方式写程序,好的可读性和可维护性。 (2)简洁:不需要额外再写一个函数或者函数对象,避免了代码膨胀和功能分散。 (3)在需要的时间和地点实现功能闭包,使程序更灵活。 lambda表达式基本概念和用法 lambda表达式定义了一个匿名函数,并且可以捕获一定范围的变量。lambda表达式的语法如下: [capture] (params) opt -> ret {body;} 其中,capture为捕获列表;params是参数表;opt为函数选项;ret为返回值类型;body是函数体。 捕获列表是将lambda外部的一些变量引入lambda内部,可以为值类型或引用类型。 auto f = [] (int a) -> int {return a + 1;}; std::cout << f(1) << std::endl; 或者省略返回值类型(c++11可以进行类型推导),直接写成 auto f = [](int a){return a+1;}; std::cout << f(1) << std::endl; 捕获列表 lambda表达式可以通过捕获列表捕获一定范围内的变量: [] 不捕获任何变量 [&] 捕获外部作用域中的所有变量

Conflicting declaration using constexpr and auto in C++11

戏子无情 提交于 2019-12-08 05:06:46
问题 I'm experimenting with C++11, constexpr and auto. I'm failing to understand why this code does not compile: template<class T, T t> struct TestEle2 { }; template<class T, T t> struct DStruct {int a;}; template<char t> struct TestEle2<char, t> { static constexpr auto f = 5; static constexpr auto g = &DStruct<char, t>::a; }; template<char c> constexpr decltype(TestEle2<char, c>::f) TestEle2<char, c>::f ; // This compiles template<char c> constexpr decltype(TestEle2<char, c>::g) TestEle2<char, c>

Is C++11 auto type dangerous? [duplicate]

烈酒焚心 提交于 2019-12-07 23:47:55
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: How much is too much with C++0x auto keyword The new keyword “auto”; When should it be used to declare a variable type? In C++11, Typing a variable auto instead of, say, int , will let the compiler automatically use the right type, deduced from its initialization context. This comes super handy in situations where the type is obvious but boring to write. Are there pitfalls to be aware of, or reasons why someone