Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++/CLI : How do I declare abstract (in C#) class and method in C++/CLI?

What is the equivalent of the following C# code in C++/CLI?

public abstract class SomeClass
{
    public abstract String SomeMethod();
}
like image 578
Lopper Avatar asked Dec 05 '09 01:12

Lopper


People also ask

Can we declare variable in abstract class C++?

No. You can only declare classes as abstract, and variables as references to classes (or as value types). And base can hold a reference to any class derived from MyBase.

How can we declare abstract class in C Plus Plus?

An abstract class contains at least one pure virtual function. You declare a pure virtual function by using a pure specifier ( = 0 ) in the declaration of a virtual member function in the class declaration.

What is abstract C?

Abstraction means displaying only essential information and hiding the details. Data abstraction refers to providing only essential information about the data to the outside world, hiding the background details or implementation.

How do we declare an abstract class in C?

You create an abstract class by declaring at least one pure virtual member function. That's a virtual function declared by using the pure specifier ( = 0 ) syntax. Classes derived from the abstract class must implement the pure virtual function or they, too, are abstract classes.


2 Answers

Just mix up the keywords a bit to arrive at the correct syntax. abstract goes in the front in C# but at the end in C++/CLI. Same as the override keyword, also recognized today by C++11 compliant compilers which expect it at the end of the function declaration. Like = 0 does in traditional C++ to mark a function abstract:

public ref class SomeClass abstract {
public:
  virtual String^ SomeMethod() abstract;
};
like image 155
Hans Passant Avatar answered Sep 27 '22 19:09

Hans Passant


You use abstract:

public ref class SomeClass abstract
{
    public:
        virtual System::String^ SomeMethod() = 0;
}
like image 32
Reed Copsey Avatar answered Sep 27 '22 20:09

Reed Copsey