Safe in C# not in C++, simple return of pointer / reference

后端 未结 7 1778
逝去的感伤
逝去的感伤 2021-01-19 22:46

C++ code:

person* NewPerson(void)
{
  person p;
  /* ... */
  return &p; //return pointer to person.
}

C# code:

person          


        
7条回答
  •  心在旅途
    2021-01-19 23:19

    Did i get this right?

    Yes.

    BTW: in C++ person p(); declares a function and will not call the default ctor of person. Just write person p;

提交回复
热议问题