简体   繁体   English

二进制&#39;=&#39;:未找到采用&#39;std :: unique_ptr类型的右侧操作数的运算符 <char [],std::default_delete<_Ty> &gt;&#39;

[英]binary '=': no operator found which takes a right-hand operand of type 'std::unique_ptr<char [],std::default_delete<_Ty>>'

I have this check and when I'm trying to get the username, it says there is no acceptable conversion from Unique_ptr to CString. 我进行了此检查,当我尝试获取用户名时,它说从Unique_ptr到CString没有可接受的转换。

Here is my code: 这是我的代码:

if (tsvn_creds.size() == 1)
    {
        std::map<CStringA,Creds>::iterator it = tsvn_creds.begin();
        if (tsvn_creds.find(it->first) != tsvn_creds.end())
        {
            Creds cr = tsvn_creds[it->first];
            user_name = cr.GetUsername();
        }
    }

Where GetUsername is: 其中GetUsername是:

std::unique_ptr<char[]> GetUsername() { return CStringUtils::Decrypt(username); }

CString user_name = NULL;

I need user_name as CString because at some point I need to append it to a CString message. 我需要user_name作为CString,因为有时需要将它附加到CString消息中。

What's wrong with the way I have it setup above? 我在上面进行设置的方式有什么问题?

Here is the error I get: 这是我得到的错误:

Error   C2679   binary '=': no operator found which takes a right-hand operand of type 'std::unique_ptr<char [],std::default_delete<_Ty>>' (or there is no acceptable conversion)

EDIT: 编辑:

I tried this solution as told in the comments: 我按照评论中的说明尝试了此解决方案:

user_name = *(cr.GetUsername());

but I get the error "illegal indirection" 但出现错误“非法间接访问”

The root of your problem is probably the CString type; 问题的根源可能是CString类型。 the error message you get is saying that the implementer(s) of CString didn't define an operator= that assigns a CString object from a unique_ptr<char[]> . 您收到的错误消息是说CString的实现operator=未定义用于从unique_ptr<char[]>分配CString对象的operator=

Based on some quick Googling, I'm guessing your CString type is this one because it's from a Microsoft library and you say you're using WinForms. 基于一些快速的Google搜索,我猜您的CString类型就是这种类型,因为它来自Microsoft库,并且您说您正在使用WinForms。 According to the documentation, you can only assign a CString from a raw pointer to a char array, that is, const unsigned char* . 根据文档,您只能将CString从原始指针分配给char数组,即const unsigned char* So to assign the result of GetUsername() to your CString user_name , you need to get the underlying raw pointer from the unique_ptr : 因此, GetUsername()的结果分配给您的CString user_name ,您需要从unique_ptr获取基础原始指针:

user_name = cr.GetUsername().get()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误C2679:binary&#39;=&#39;:找不到运算符,它接受类型&#39;std :: vector &lt;_Ty&gt; *&#39;的右手操作数(或者没有可接受的转换) - error C2679: binary '=' : no operator found which takes a right-hand operand of type 'std::vector<_Ty> *' (or there is no acceptable conversion) 错误 C2679:二进制“&lt;&lt;”:未找到采用“std::vector”类型的右侧操作数的运算符<char,std::allocator<char> &gt;&#39; - error C2679: binary '<<': no operator found which takes a right-hand operand of type 'std::vector<char,std::allocator<char>>' 错误C2679:二进制&#39;&lt;&lt;&#39;:找不到运算符,该运算符使用类型为&#39;std :: string&#39;的右侧操作数 - error C2679: binary '<<':no operator found which takes a right-hand operand of type 'std::string' 错误c2679.Error 1错误C2679:二进制&#39;&lt;&lt;&#39;:找不到运算符,它采用&#39;std :: vector &lt;_Ty&gt;&#39;类型的右手操作数 - error c2679.Error 1 error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::vector<_Ty>' 重载&lt;&lt;在C ++错误中的运算符:::二进制&#39;&lt;&lt;&#39;:找不到使用类型为&#39;const std :: string的右侧操作数的运算符 - Overloading the << operator in C++ error ::: binary '<<' : no operator found which takes a right-hand operand of type 'const std::string 错误:C2679二进制&#39;==&#39;:未找到采用类型为&#39;const std :: string&#39;的右侧操作数的运算符(或者没有可接受的转换 - Error:C2679 binary '==': no operator found which takes a right-hand operand of type 'const std::string' (or there is no acceptable conversion 错误C2679:二进制&#39;&gt;&gt;&#39;:找不到哪个运算符采用&#39;std :: string&#39;类型的右手操作数(或者没有可接受的转换) - error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion) 错误C ++ 2679(二进制&#39;&gt;&gt;&#39;:找不到使用类型为&#39;const std :: string&#39;的右侧操作数的运算符(或没有可接受的转换)) - Error C++ 2679 (binary '>>': no operator found which takes a right-hand operand of type 'const std::string' (or there is no acceptable conversion)) 二进制&#39;==&#39;:未找到采用&#39;std :: pair类型的左手操作数的运算符 <const _Kty,_Ty> &#39; - binary '==': no operator found which takes a left - hand operand of type 'std::pair<const _Kty,_Ty>' 二进制&#39;[&#39;:找不到运算符,它接受类型&#39;const std :: map &lt;_Kty,_Ty&gt;&#39;的左手操作数 - binary '[' : no operator found which takes a left-hand operand of type 'const std::map<_Kty,_Ty>'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM