请问有人可以帮我解决这个调试问题吗? [英] pls can anyone help me with this debugging problem?

查看:68
本文介绍了请问有人可以帮我解决这个调试问题吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请注意我收到以下错误消息,但我无法解决问题:



1.错误c2662:'Function :: Evaluate'无法将'this'指针转换为'const函数转换为Fumction&,



2.错误C2663'函数:: GetReference'2重载没有合法转换'this '指针。



3.错误C2248 :: CObject :: operator ='无法访问Class'CObject'中声明的私有成员。

该诊断发生在编译生成的函数'CList< type>中。 & CList< type> :: operator =(const CList< type>&)'。

看来,发布的代码量是人们的伤痕累累

所以我决定退出代码。

Pls I am getting the following error messages and I haven't been able to fix the problem:

1. error c2662: 'Function::Evaluate ' cannot convert 'this' pointer to 'const Function to Fumction &,

2.Error C2663 'Function::GetReference' 2 overloads have no legal conversion for 'this' pointer.

3.Error C2248: :CObject::operator=' cannot access private member declared in Class 'CObject'.
This diagnostic occurred in compilet generated function 'CList<type> &CList<type>::operator = (const CList<type> &)'.
It appears the volume of code IS posted is scarimg people away
So I decided to romove the code.

推荐答案

1。方法Function :: Evaluate()声明为const,但函数的实现要么尝试修改实例的成员,要么调用非const的成员函数。



解决方案:检查函数实现中的哪些元素是非const的,并将实现更改为仅使用const成员,或者,如果您真的想要更改值,请从函数签名中删除const限定符。



2.编译器发现函数Function :: GetReference()有两个重载,但函数签名都没有与它的使用方式相匹配



解决方案:由于错误提到'this'指针,它可能只是1-i的后续错误。即编译器无法匹配其中一个重载的原因可能是当前的'this'是const,但是没有函数重载是const函数。如果不是这种情况,请检查错误消息所引用的代码行,并确保调用该函数的方式与您要调用的函数的签名相匹配。



3.虽然错误消息本身是清楚的,但消息指向的代码可能无法提供问题所在的立即提示,因为它可能位于不属于您自己的代码中:似乎您定义了CObject类型的对象列表。类列表本身声明了一个赋值运算符,它复制列表的内容,因此需要访问它的元素的赋值运算符,在本例中为CObject :: operator =()。由于该成员函数被声明为私有(或受保护),因此CList实现无法访问它,从而导致出现错误消息。



解决方案:我不确定是否您正在使用的类CObject是您自己定义的类,或者是由MFC等框架提供的类。我认为这是后者。在这种情况下,定义CObject类型的元素列表没有任何意义!你打算做的是定义从CObject派生的某些(未知)类型的元素列表。如果这个假设是准确的,那么正确的做法是定义一个指向 CObject指针的元素列表。



PS:全部只需查看错误消息并理解其含义,即可得出这些答案和解决方案。在MSDN上查找错误代码也有帮助。也就是说,如果您只是发布了这些错误消息指向的代码行,那么提供更准确的建议会更容易!
1. The method Function::Evaluate() is declared as const, but the implementation of the function either tries to modify a member of the instance, or calls a member function that is not const.

Solution: Check what element(s) in the function implementation are non-const and either change the implementation to only use const members, or, if you really mean to change values, remove the const qualifier from the function signature.

2. The compiler found two overloads for the function Function::GetReference(), but neither function signature matches how it is used

Solution: since the error mentions the 'this' pointer, it may just be a subsequent error of 1 - i. e. the reason that the compiler couldn't match one of the overloads may be that 'this' in the current is const, but none of the function overloads is a const function. If that is not the case, check the line of code that the error message refers to and make sure that the way you call the function matches the signature of the function that you mean to call.

3. While the error message itself is clear, the code the message points to may not provide an immediate hint where the problem lies, as it may be in code that is not your own: it seems that you defined a list of objects of type CObject. The class list itself declares an assignment operator which copies the contents of the list, and therefore needs to access the assignment operator of it's elements, in this case CObject::operator=(). Since that member function was declared private (or protected), the CList implementation cannot access it, resulting in the error message.

Solution: I'm not sure if the class CObject you're using is one you defined yourself, or one provided by a framework such as MFC. I assume it's the latter. In this case, defining a list of elements of type CObject doesn't make any sense! What you meant to do is define a list of elements that are of some (unknown) type derived from CObject. If that assumption is accurate, the correct thing to do is define a list of elements of type pointer to CObject instead.

P.S.: all these answers and solutions can be derived from just looking at the error messages and understanding their meaning. Looking the error codes up on MSDN helps, too. That said, it would be easier to give more accurate advice if you had simply posted the lines of code that these error messages point to!


这篇关于请问有人可以帮我解决这个调试问题吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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