腾讯云
开发者社区
文档
建议反馈
控制台
首页
学习
活动
专区
工具
TVP
最新优惠活动
文章/答案/技术大牛
搜索
搜索
关闭
发布
登录/注册
精选内容/技术社群/优惠产品,
尽在小程序
立即前往
文章
问答
(9999+)
视频
沙龙
1
回答
将声明
的
“auto”
std
::
shared_ptr
<Derived>传递给
std
::
shared_ptr
<Base>&
c++
、
c++11
用g++ -
std
=c++11 -pedantic-errors -Wall -Wextra -g编译
std
::cout<< "foo()\n";} int main(
浏览 0
提问于2021-03-13
得票数 1
回答已采纳
1
回答
对
类型
'A *‘
的
非
常数
左
值
引用
不能
绑定
到
不相关
类型
'
std
::
shared_ptr
<A>’
的
值
c++
、
shared-ptr
、
reference-binding
首先,有一堆类似的帖子,看起来它们是完全相同
的
问题,但我发现它们与我
的
问题不同。在我
的
C++生活中,我第一次尝试使用智能指针。我在使用智能指针进行多态性时遇到了麻烦。准确地说,我正在尝试将以下原始指针(如下所示代码
的
第15行)转换为智能指针: class Maze { Maze() = default; wheeledMaze.BuildStack(wheeledRobotInMaze);
浏览 23
提问于2019-05-13
得票数 2
回答已采纳
2
回答
将指针传递给int*&并获取编译错误
c++
为什么fun(p)可以工作,而fun(&i)
不能
?#include<iostream> { { int
浏览 13
提问于2020-05-01
得票数 3
回答已采纳
4
回答
组合复制和移动
的
两个构造函数
c++
、
templates
、
c++11
、
move-semantics
、
perfect-forwarding
目前,我
的
一个玩具类模板有两个看起来非常相似的构造函数:{} {}optional(U&& x) construct(
std
::forward<U>(x)); }
浏览 0
提问于2011-09-12
得票数 7
回答已采纳
1
回答
有没有可能在没有
类型
推断
的
情况下实现类似转发
引用
的
行为?
c++
、
c++11
、
language-lawyer
、
rvalue-reference
、
perfect-forwarding
最近,我了解了通用(或转发)
引用
。它们只适用于
类型
推导,如模板或auto / decltype。 当我使用
左
值
引用
(&)时,我
不能
将它
绑定
到
右
值
(临时)对象。当我使用一个右
值
引用
(&&)时,我
不能
将它
绑定
到
左
值
对象。转发
引用
可以与非
常数
<em
浏览 1
提问于2017-01-17
得票数 4
回答已采纳
2
回答
如何返回由10个字符串组成
的
数组
的
引用
c++
这是C++ Primer 5
的
一次练习。我不知道怎么解决它?为一个函数编写声明,该函数返回一个由十个字符串组成
的
数组
的
引用
,而不使用尾随返回、解密
类型
或
类型
别名。我
的
密码:#include <string> {
浏览 2
提问于2014-06-10
得票数 2
回答已采纳
2
回答
为什么函数列表中返回
的
"make_share<Type>“
值
是rvalue?
c++
这是我
的
代码: public: Quote(const string& bookitem.add_item(make_shared<Quote>("aaaa", 1)); //here is the problem is } 当我修改它时,我得到了错误
的
消息,
不能
将‘
std
:
浏览 5
提问于2022-01-06
得票数 0
回答已采纳
2
回答
带有构造函数参数
的
单例
c++
、
xcode
、
design-patterns
、
singleton
在尝试创建类
的
单个实例时,需要对类
的
名称进行全局访问和修改,但我认为实现文件中
的
代码存在一些与语法相关
的
问题(我认为)。编译时,返回语句会出现错误: class Single{
std
::strin
浏览 6
提问于2016-05-24
得票数 2
回答已采纳
1
回答
如果参数
类型
为"const int“,为什么无法编译tr1::bind
constants
、
bind
vector>#include <iterator>#include <deque>using namespace
std
::tr1::placeholders;voidfor_each_x(tr1::bind(tr1::funct
浏览 0
提问于2009-11-05
得票数 0
回答已采纳
3
回答
为什么
不能
用函数返回
的
unique_ptr替换unique_ptr?
c++
、
visual-studio-2012
、
unique-ptr
下面的代码将抛出一个警告:
std
::unique_ptr<T> foo() { return
std
::unique_ptr<T>( new T ); }myVar.swap(foo()); 我想知道处理这种情况
浏览 0
提问于2012-08-25
得票数 2
回答已采纳
1
回答
将istream转换为ifstream?
c++
我正在学习为指定项目提供
的
教程。inf, ostream& outf) ifstream& inf1 = inf;} 这两行都给出了一个错误:
对
类型
'ifstream‘(又名'basic_ifstream')
的
非
const lvalue
引用
不能
绑定
到
不相关
类型
浏览 6
提问于2014-08-12
得票数 0
2
回答
为什么模板前
的
常量参数不起作用
c++
、
templates
我很困惑为什么下面的代码
不能
工作?编译器说:错误:无法将
类型
为‘int&’
的
非
常数
左
值
引用
绑定
到
类型
为‘int’6| const T a=1
的
右
值
; template<typename T>{ const
浏览 24
提问于2021-08-16
得票数 0
3
回答
在包含vector<bool>
的
类中重新定义运算符[]
c++
、
vector
、
operators
我在我
的
类中重新定义operator[]时遇到了问题,这个类将向量作为私有成员。所以计划是有布尔向量,它将只包含真或假
的
值
。这是最小
的
代码,你可以理解我
的
问题。class A{
std
::vector<bool> _object; bool& operator[](size_t i) {return_object[i];};编译器错误是:
对
bool
类型
<em
浏览 0
提问于2016-01-08
得票数 0
2
回答
如何在右
值
引用
中包装指针?
c++
、
c++11
、
operator-overloading
、
rvalue-reference
std
::
shared_ptr
::operator*通过
左
值
引用
返回,而对于重载指针如操作给出
的
答案是通过
左
值
引用
返回。AdjacencyList::vertex_type::addVertex‘:无法将参数1从'AdjacencyList::vertex_type’转换为‘AdjacencyList::vertex_type &&':你
不能
将
左
值</em
浏览 0
提问于2013-04-10
得票数 2
回答已采纳
2
回答
从对象
的
向量返回一个对象作为
引用
c++
、
c++20
total_time =
std
::chrono::duration_cast(dur); } {
std
::uniform_real_distributionrepeats, items, timeOne) << MS_UNIT <&
浏览 41
提问于2021-02-28
得票数 0
回答已采纳
4
回答
如何使模板右
值
引用
参数只
绑定
到
右
值
引用
?
c++
、
rvalue-reference
我
的
一个类希望接收其他
类型
的
文件描述符包装器并获得所有权,所以它类似于{ void receive_ownership(T&& t) // taking file descriptor of t, and clear t}; 它必须处理多个
不相关
的
类型
,所以receive_ownership必须是一个模板,而且
浏览 1
提问于2011-10-23
得票数 43
回答已采纳
3
回答
关于在临时函数中使用string::swap()
的
问题
c++
、
string
、
stl
、
stream
、
temporary
'
std
::basic_string<char,
std
::char_traits<char>,
std
::allocator<char> >::swap(
std
::basic_string<char,
std
::char_traits<char>,
std
::allocator<char> >)' basic_string.tcc:496: note: candidates are: void <
浏览 0
提问于2010-07-13
得票数 5
回答已采纳
2
回答
模板参数演绎-T已推导并使用T&&
c++
、
templates
、
c++11
对于示例,void function(T&& arg) 有人能详细解释一下如何结束函数签名变成T&
的
左
值
和T&&传递
的
右
值
吗?我知道不知何故(需要标准线),在
左
值
的
情况下,T -> T&,在重
值
的
情况下,T -> T,然后通过组合&和&&,它会产生lvalue/rva
浏览 1
提问于2012-10-23
得票数 2
回答已采纳
2
回答
错误C2440:‘初始化’:无法从'
std
::vector<_Ty>‘转换为'const
std
::vector<_Ty> &`
c++
、
boost
Question1>为什么下面的代码
不能
工作?#include <vector>{}; {
std
::vector<b
浏览 28
提问于2013-02-27
得票数 3
1
回答
在所需
的
抽象基
引用
不起作用
的
情况下传递临时创建派生对象?
c++
、
constructor
、
reference
我想有一些关于临时对象
的
东西我不理解。class F { C getC() { return C(); };public:}; 这是可行
的
:
浏览 0
提问于2012-06-12
得票数 0
回答已采纳
点击加载更多
扫码
添加站长 进交流群
领取专属
10元无门槛券
手把手带您无忧上云
相关
资讯
智能指针:让C+程序更加安全和高效的神器
c+的左值(lvalue),右值(rvalue),移动语义(move),完美转发(forward)
C+11 shared_ptr智能指针(超级详细)
请问C+11有哪些新特性?
C+之右值引用
热门
标签
更多标签
活动推荐
运营活动
广告
关闭
领券