https://kotlinlang.org logo
#language-proposals
Title
# language-proposals
a

anlex N

12/10/2023, 3:01 PM
Copy code
c++
// deriv_VirtualFunctions2.cpp
// compile with: /EHsc
#include <iostream>
using namespace std;

class Base {
public:
  virtual void NameOf();  // Virtual function.
  void InvokingClass();  // Nonvirtual function.
};

// Implement the two functions.
void Base::NameOf() {
  cout << "Base::NameOf\n";
}

void Base::InvokingClass() {
  cout << "Invoked by Base\n";
}

class Derived : public Base {
public:
  void NameOf();  // Virtual function.
  void InvokingClass();  // Nonvirtual function.
};

// Implement the two functions.
void Derived::NameOf() {
  cout << "Derived::NameOf\n";
}

void Derived::InvokingClass() {
  cout << "Invoked by Derived\n";
}

int main() {
  // Declare an object of type Derived.
  Derived aDerived;

  // Declare two pointers, one of type Derived * and the other
  // of type Base *, and initialize them to point to aDerived.
  Derived *pDerived = &aDerived;
  Base  *pBase  = &aDerived;

  // Call the functions.
  pBase->NameOf();      // Call virtual function.
  pBase->InvokingClass();  // Call nonvirtual function.
  pDerived->NameOf();    // Call virtual function.
  pDerived->InvokingClass(); // Call nonvirtual function.
}
how to convert this c++ to kotlin?
🚫 1
a

Alejandro Rios

12/10/2023, 4:00 PM
Please take a moment to read the channel description before posting a question
plus1 5
a

anlex N

12/11/2023, 2:03 AM
I know, but nobody help me.