Tangible Software Solutions

The Most Trusted Name in Source Code Conversion

C++ Equivalent to Java Functional Interfaces

The closest C++ equivalent to Java's functional interfaces are C++ function pointers.

Original Java:

@FunctionalInterface
public interface FooFunctional
{
   void invoke();
}

public class UseFunctionalInterface
{
   void method()
   {
      FooFunctional funcVar = () -> voidMethod();
      funcVar.invoke();
   }
   void voidMethod()
   {
   }
}

Equivalent C++:

using FooFunctional = std::function <void()>;

class UseFunctionalInterface
{
public:
   virtual void method()
   {
      FooFunctional funcVar = [&] ()
      {
         voidMethod();
      };
      funcVar();
   }
   virtual void voidMethod()
   {
   }
};

If you need to convert from Java to C++ and you are depending on the results being reliable and accurate, then you will want to have Java to C++ Converter, the best Java to C++ converter, at your fingertips.

Copyright © 1997 - 2017 Tangible Software Solutions Inc.