0

Hi,

this might be kidish to people over here , am trying to migrate code from c++ to C# where am new to CPP , so guys please help me out what this below code exactly mean .

int myFunc (int a, int b)=0;

Thanks for your time .

3
Contributors
3
Replies
15
Views
2 Years
Discussion Span
Last Post by sepp2k
0

It declares a function called myFunc which returns an int and takes two int parameters. This function has to also be a virtual member function of some class, because the =0 part at the end is the "pure-specifier" which means that the function does not have a definition (implementation) which is only allowed for virtual member functions, making them pure virtual functions. With pure virtual functions, you force the derived classes to provide an implementation for them, also making the base-class an abstract class, meaning that only derived class objects can be created. Abstract classes are sort of the C++ flavor of what is traditionally called "Interfaces" in the Java/C# OOP terminology.

0

Hi,

thankyou so much for the reply, and if am rewriting this function in c# , should i need to write them necessarily as virtual ?.please advise.
thanks

0

Abstract classes are sort of the C++ flavor of what is traditionally called "Interfaces" in the Java/C# OOP terminology.

I'd say they're the C++ flavor of what Java and C# call abstract classes. A C++ abstract class wouldn't translate to a Java/C# interface unless all the members are purely virtual.

if am rewriting this function in c# , should i need to write them necessarily as virtual

If you declare the method as abstract, it's automatically virtual, so you don't need to spell that out explicitly.

Edited by sepp2k

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.