Error C2440: cannot convert from type to type

Yesterday I got this error in a new C++/CLI project:
 

Error 1 error C2440: 'return' : cannot convert from 'ZXNewtonCP::LayoutManager' to 'ZXNewtonCP::LayoutManager' d:\proyectos\rfog\zxnewtoncp\zxnewtoncp\Config.h 17

LayoutManager is a managed class, and is instantiated in class config as a stack type, not a reference or pointer.

My intention was to return a reference, but I mistake the typing and got that error. I don’t know if system can return a complete class instead a reference, but the error sounds cryptic and obscure.< xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

 

Public ref class LayoutManager {…}

 

Public ref class Config

{

LayoutManager layoutManager;

property LayoutManager GetLayout

{

         LayoutManager get(void) {return layoutManager;}

}

 



Answer this question

Error C2440: cannot convert from type to type

  • Phillip M. Hoff

    Please log a suggestion issue at http://lab.msdn.microsoft.com/productfeedback/default.aspx.

    Thanks,
      Ayman Shoukry
      VC++ Team

  • JustDave

    No! You can not return a "complete" class. a ref class is always referenced with a handle ^.

    What do you want to do Do you want to create a new object You need to use gcnew/new for this.

  • Bartosz Bien

     Ayman Shoukry wrote:
    Please log a suggestion issue at <a href="http://lab.msdn.microsoft.com/productfeedback/default.aspx">http://lab.msdn.microsoft.com/productfeedback/default.aspx</a>.<br /><br />Thanks,<br />&nbsp; Ayman Shoukry<br />&nbsp; VC++ Team


    I've done yet. Thanks.

  • soundman32

    No, it is right for me.

    My comment is about the cryptic error message to say that I cannot return a complete class. Message error could say "Error C<bla>: Is not allowed to return a complete[or stack allocated or non-referenced] managed class. Return a reference instead", or similar.

  • Dennis Rose

    This sounds like something you should open a new bug on.  I've opened one or two asking for clearer diagnostics myself.

    Brian


  • cgMarcos

    Thanks for taking the time to log the issue!

    Thanks,
      Ayman Shoukry
      VC++ Team

  • Error C2440: cannot convert from type to type