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 .
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 .
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.
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
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.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.