开发者

Error : 'CPtrList::AddTail' : 2 overloads have no legal conversion for 'this' pointer

How to overcome this?

Here is my code

Here is my code

ObjectList.h

#pragma once
#include "LogData.h"
 typedef  CTypedPtrArray<CPtrList , CLog *> CLogData;
 class CObjectList
 {
   public:

 CLogData m_logData;
   public:
 CObjectList();
CLogData GetLog();
  };
开发者_如何学Python

ObjectList.cpp

 #include "stdafx.h"
 #include "LogData.h"

 CObjectList::CObjectList()
  {
  }

  CLogData CObjectList::GetLog()
 {
   return m_logData;
  }

While access the content in another file like these show error:

       CObjectList* threadinfo;
    threadinfo = (CObjectList*)ptr;
       threadinfo->GetLog().AddTail(log);

Regards,

Karthik


It is very hard to tell, seeing as your post is very disjointed.

The error message sounds like one you get when you try to violate const-ness.

e.g.

class C
{
public:
    void a();
    void b() const;
};

void func()
{
    C c0;
    c0.a();  //  OK
    c0.b();  //  OK

    const C c1;
    c1.a();  // violates const-ness : compiler error
    c0.b();  // this is OK as b() is a const function.
}

If you have a const object, you can only call const methods.

You get many variations on this. e.g.

class D
{
public:
    void e();
};

class F
{
public:
    void g() const
    { 
        m_d.e();  // This line is an error
    }
    D m_d;
};

void func()
{
    F f;
    f.g();
}

In the above, F::g() is a const function. It may be called on const objects. But even if you call it with a non-const object, it guarantees not to change the object. But F::g() calls D::e() on the local object m_d. D:e() is not a const function, so the compiler doesn't know if it will modify m_d -- therefore the compiler will give an error.

It can get complex.

So I guess that you have a problem with const-ness. It might be a straightforward one or it may be a complex one. If you can post some complete code that shows the same problem, then it will be easier to help you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜