非常量引用类型的无效初始化中出错.在Linux操作系统中使用c++代码.GCC编译器
error in invalid initialization of non-const reference type . Using c++ code in Linux OS. GCC Compiler
vector<string>& temp = var_obj.funct();
在Linux中不工作,但&
除外,它工作正常。vector<string> temp = var_obj.funct();
错误:类型的非常量引用的初始化无效'std::vector,std::分配器>,std::分配程序,std::分配器>>&'从临时类型为"std::vector",std::allocater>,std::分配器,std::分配器>>'
问题是函数返回的值是临时的。您无法生成对它的引用,因为它只是暂时存在的。函数调用后,该值将消失。
相反,试试这个:
vector<string> temp = var_obj.funct();
vector<string> &temp2 = temp;
现在您有了一个名为temp2
的引用。
相关文章:
- 在C++中设置基于操作系统的文件路径
- 如何在工厂方法中返回指向基于基础操作系统的派生类的有效指针
- WideCharToMultiByte在英语操作系统上不转换日语
- 如何在 Windows 操作系统中在 geany 中安装插件
- 操作系统平台支持宏和提升库
- 从utsname找出Linux操作系统名称
- 为什么 free() 函数不将内存返回给操作系统?
- 我可以让编译器忽略特定于操作系统的方法吗?
- 有没有办法获取用户操作系统的ANSI转义码?
- 测试操作系统时执行程序集"sti"时虚拟框崩溃
- 如何应用 printers.py 修改?(Linux操作系统)
- LINUX 操作系统上的错误:令牌之前预期的构造函数、析构函数或类型转换'('?
- 当PSO细粒度策略对使用AdsGetObject MSDN API的Windows操作系统生效时,如何获取用户密码到期日
- 操作系统如何检测进程崩溃
- 检查操作系统兼容性
- 操作系统 (Linux) 在使用 boost::asio::generic::raw_protocol::socket
- 检测到由于操作系统内存不足而导致子进程终止
- 在Windows 10操作系统中扩展控制台
- 如何从支持linux/mac操作系统的第三方代码为我的c#项目创建dll
- 读取USB与操作系统、C++之间传输的数据