Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    why my interface is sealed in maxon::Result?

    Cinema 4D SDK
    r25 c++
    3
    4
    581
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Y
      yushang
      last edited by

      Hi guys,
      I'm following the maxonsdk.module listed in here. Which declare a SimpleNumberInterface and implement it with SimpleNumberImpl. I mimic the steps as follow

      1. projectdefinition.txt
      Platform=Win64;OSX;Linux
      Type=DLL
      APIS=core.framework
      stylecheck=false
      ModuleId=net.yu.myp
      
      1. myifc.h
      #pragma once
      #include "maxon/object.h"
      class MyIfc : MAXON_INTERFACE_BASES(maxon::ObjectInterface) {
      MAXON_INTERFACE(MyIfc,MAXON_REFERENCE_NORMAL,"net.yu.interface.myifc");
      public:
        MAXON_METHOD void Hello();
      };
      #include "myifc1.hxx"
      MAXON_DECLARATION(maxon::Class<MyIfcRef>, MyIfcDecl, "net.yu.myifcdecl");
      #include "myifc2.hxx"
      
      1. myifc.cpp
      #include "myifc.h"
      class MyIfcImpl : public maxon::Component<MyIfcImpl,MyIfc> {
         MAXON_COMPONENT();
      public:
        MAXON_METHOD void Hello() {
        }
      };
      MAXON_COMPONENT_CLASS_REGISTER(MyIfcImpl, MyIfcDecl);
      
      1. main.cpp
      #include "myifc.h"
      extern "C"
      __declspec(dllexport)
      int c4d_main(int action, void* p1, void* p2, void* p3) {
        MyIfcRef ifc = MyIfcDecl().Create();   // A
        return 1;
      }
      

      At line A , I got the following error

      error C2440: 'initializing': cannot convert from 'maxon::Result<MyIfcRef>' to 'MyIfcRef'
      

      How does this happen? Many thanks!

      ferdinandF 1 Reply Last reply Reply Quote 0
      • M
        m_adam
        last edited by

        This post is deleted!
        1 Reply Last reply Reply Quote 0
        • ferdinandF
          ferdinand @yushang
          last edited by ferdinand

          Hello @yushang,

          thank you for reaching out to us. Please have a look at our Error System documentation. You are missing an iferr_return and an error scope in your code.

          int c4d_main(int action, void* p1, void* p2, void* p3) 
          {
            // Errors imply being propagated upwards in a call chain. When we want to terminate such chain,
            // i.e., have this function return `int` (you should use Int32 as int is ambiguous) instead of
            // `maxon::Result<maxon::Int32>` we can use a custom error handler to handle errors being thrown.
            // When the return type is `maxon::Result<T>` we can just use an `iferr_scope;` instead.
            iferr_scope_handler
            {
                DebugOutput("c4d_main failed with '@'", err);
                return 0;
            };
          
            // Create methods return a `maxon::Result<T>` object, i.e., either the value or the error. The
            // `iferr_return` keyword will unpack that error for us.
            MyIfcRef ifc = MyIfcDecl().Create() iferr_return;
          
            // Technically possible, but bad code:
            maxon::Result<MyIfcRef> result = MyIfcDecl().Create();
          
            // Can make sense in some cases, but should be generally avoided:
            MyIfcRef ifc = MyIfcDecl().Create() iferr_ignore("We don't care about the error here."_s);
          
            // Finally, there is a special form of branching that allows to handle errors in a more detailed way:
            ifnoerr (MyIfcRef ifc = MyIfcDecl().Create())
            {
              // Runs when the creation was successful.
            }
            
            iferr (MyIfcRef ifc = MyIfcDecl().Create())
            {
              // Would run when the creation failed.
            }
          
            return 1;
          }
          

          Cheers,
          Ferdinand

          MAXON SDK Specialist
          developers.maxon.net

          Y 1 Reply Last reply Reply Quote 0
          • Y
            yushang @ferdinand
            last edited by

            @ferdinand cool. this really helpful!

            1 Reply Last reply Reply Quote 0
            • First post
              Last post