Well I think my lack of knowledge on OOP is quite deep.

I was just experimenting with [this 
example](https://play.nim-lang.org/#ix=4f8I), which fails. You cannot convert 
objects like that.
    
    
    type
      Person = object of RootObj
        name: string
      
      Student = object of Person
    
    var a:Person
    var b:Student
    b.name = "joe"
    a = b
    
    
    Run

The [following works](https://play.nim-lang.org/#ix=4f8J):
    
    
    type
      Person = ref object of RootObj
        name: string
      
      Student = ref object of Person
    
    var a = new Person
    var b = new Student
    b.name = "joe"
    a = b
    b.name = "peter"
    assert b.name == "peter"
    assert a.name == "peter"
    assert (a of Person)
    assert (b of Student)
    
    
    Run

The first issue that I have above, is trying to mimic this behaviour in C++:
    
    
    // Geom_CartesianPoint inherits from Geom_Point
    Handle(Geom_Point) aPnt1;
    Handle(Geom_CartesianPoint) aPnt2;
    aPnt2 = new Geom_CartesianPoint();
    aPnt1 = aPnt2; // OK, standard assignment
    
    
    Run

In my bindings, `Geom_CartesianPoint` inherits from `Geom_Point`. But their 
respective handles are unreleated.

In Nim:
    
    
    import occt
    
    var aPnt1: Handle[Geom_Point]
    var aPnt2: Handle[Geom_CartesianPoint]
    aPnt2 = newHandle( cnew newGeomCartesianPoint(1.0,2.0,3.0) )
    #aPnt1 = aPnt2  # This fails
    
    
    Run

fails.

If I replace the last line with:
    
    
    aPnt1 = cast[Handle[Geom_Point]](addr aPnt2)  # This fails as well
    
    
    Run

it also fails:
    
    
    /home/jose/.cache/nim/tmp01_d/@mtmp01.nim.cpp: In function 'void 
NimMainModule()':
    /home/jose/.cache/nim/tmp01_d/@mtmp01.nim.cpp:117:92: error: use of deleted 
function 'NimMainModule()::<unnamed union>::<constructor>()'
      117 |         union { TY__34Wf6HfOat7G9bBA2jRAzyA* source; 
TY__7y8d4b9bdzRBHHJhUtf9af9ag dest; } LOC1;
          |                                                                     
                       ^~~~
    /home/jose/.cache/nim/tmp01_d/@mtmp01.nim.cpp:117:15: note: 
'NimMainModule()::<unnamed union>::<constructor>()' is implicitly deleted 
because the default definition would be ill-formed:
      117 |         union { TY__34Wf6HfOat7G9bBA2jRAzyA* source; 
TY__7y8d4b9bdzRBHHJhUtf9af9ag dest; } LOC1;
          |               ^
    /home/jose/.cache/nim/tmp01_d/@mtmp01.nim.cpp:117:84: error: union member 
'NimMainModule()::<unnamed union>::dest' with non-trivial 
'opencascade::handle<T>::handle() [with T = Geom_Point]'
      117 |         union { TY__34Wf6HfOat7G9bBA2jRAzyA* source; 
TY__7y8d4b9bdzRBHHJhUtf9af9ag dest; } LOC1;
          |                                                                     
               ^~~~
    /home/jose/.cache/nim/tmp01_d/@mtmp01.nim.cpp:117:92: error: use of deleted 
function 'NimMainModule()::<unnamed union>::~<constructor>()'
      117 |         union { TY__34Wf6HfOat7G9bBA2jRAzyA* source; 
TY__7y8d4b9bdzRBHHJhUtf9af9ag dest; } LOC1;
          |                                                                     
                       ^~~~
    /home/jose/.cache/nim/tmp01_d/@mtmp01.nim.cpp:117:15: note: 
'NimMainModule()::<unnamed union>::~<constructor>()' is implicitly deleted 
because the default definition would be ill-formed:
      117 |         union { TY__34Wf6HfOat7G9bBA2jRAzyA* source; 
TY__7y8d4b9bdzRBHHJhUtf9af9ag dest; } LOC1;
          |               ^
    compilation terminated due to -fmax-errors=3.
    Error: execution of an external compiler program 'g++ -c -std=gnu++14 
-funsigned-char  -w -fmax-errors=3 -fpermissive -I/usr/include/opencascade/   
-I/home/jose/.choosenim/toolchains/nim-1.6.6/lib 
-I/home/jose/src/nimlang/occt.nim/examples -o 
/home/jose/.cache/nim/tmp01_d/@mtmp01.nim.cpp.o 
/home/jose/.cache/nim/tmp01_d/@mtmp01.nim.cpp' failed with exit code: 1
    
    
    Run

How can I convert the references from one type to the other? 

Reply via email to