如何将简单对象值分配给引用对象? [英] How to assign simple object value to reference object?

查看:68
本文介绍了如何将简单对象值分配给引用对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们,



我一度陷入困境。请帮我解决这个问题。

我将一个引用对象传递给一个函数,经过一些计算后我将简单的对象值赋给引用对象。在这里我收到错误



错误C2582:'运营商='功能在'CMatroxAudioExtractor'中不可用



两个对象属于同一类。一个是参考,另一个很简单。

请告诉我如何解决这个错误。



这是代码。



Hi friends,

I stuck at one point. Please help me to resolve this.
I am passing a reference object to a function and after some calculation I am assigning the simple object value to reference object. Here I am getting error as

error C2582: 'operator =' function is unavailable in 'CMatroxAudioExtractor'

Both objects are of same class. One is reference and other one is simple.
Please tell me how to resolve this error.

Here is the code.

HRESULT CMatroxWriter::ImportAIFFAudio(CMatroxAudioExtractor& matroxAudioExtractor)
{
         HRESULT hr = S_OK;
         CMatroxAudioExtractor obmatroxAudioExtractor(strVideoPath)

         if(bIsQTRefFile)
		matroxAudioExtractor = obmatroxAudioExtractor;

         return hr;
}

推荐答案

错误消息说明了一切:CMatroxAudioExtractor类没有公共分配运算符(operator =) ,即这个类的设计者不希望任何人将另一个对象目录分配给该类的对象。这可能有几个原因,例如因为对象太复杂而将另一个对象复制到此对象会是一个严重的性能问题。



看一看CMatroxAudioExtractor类的文档,并查找成员函数,允许您以适合您需要的方式修改对象,而不是用新的替换它。
The error message says it all: The CMatroxAudioExtractor class has no public assignement operator ("operator="), i.e. the designers of this class did not want that anybody assign another object directory to an object of this class. This can have several reasons, for example because the object is so complex that it would be a severe performance problem to copy another object to this one.

Take a look at the documentation of the CMatroxAudioExtractor class and look for member functions that allow you to modify the object in a way that suits your needs instead of replacing it with a new one.


您没有分配'引用的对象'。您正在呼叫复制分配操作员 [ ^ ],由于某种原因(我不知道)不可用(即编译器无法为您生成)。

如果你需要'分配一个引用'那么你应该使用一个指针(并相应地改变你的代码)。
You are not assigning 'an object to a reference'. You are calling the copy assignment operator[^], that, for a some reason (unknown to me) is unavailable (that is the compiler cannot generate for you).
If you need to 'assign a reference' then you should use a pointer (and, accordingly, change a bit your code).


这篇关于如何将简单对象值分配给引用对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆