Skip to content

Wrong type of return, C++ #224

@polidobj

Description

@polidobj

Another C++ problem, in the GetPointer function elm is a shared pointer in the C++ output when it's requested to be simple pointer. Since the function is returning a simple pointer. So it ends up trying to return the shared pointer instead of the simple pointer.


class TestItemClass
{
  public string() Name;
}

class TestClass
{
  SortedDictionary<string(), TestItemClass#>() Items;

  internal TestItemClass!? GetPointer!(int Number) throws Exception
  {
    if(Number < 1 || Number > Items.Count)
      throw Exception("Number out of range");
    int count = 0;
    foreach((string name, TestItemClass!? elm) in Items)
    {
      count++;
      if(count == Number)
        return elm;
    }
    throw Exception("bad number."); //should never reach this due to the number check above
  }

}

This one I can at least work around by changing elm from a simple pointer to a shared pointer. (from ! to #) Then it correctly returns elm.get().

Metadata

Metadata

Assignees

Labels

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions