11

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

public abstract class SomeClass
{
    public abstract String SomeMethod();
}
Lopper
  • 3,499
  • 7
  • 38
  • 57

2 Answers2

22

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;
};
Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
7

You use abstract:

public ref class SomeClass abstract
{
    public:
        virtual System::String^ SomeMethod() = 0;
}
Reed Copsey
  • 554,122
  • 78
  • 1,158
  • 1,373
  • Is there any difference between declaring "SomeMethod() = 0" and "SomeMethod() abstract"? – Lopper Dec 05 '09 at 01:44
  • Nope. The Method() = 0 is the non-C++/CLI (just stnadard C++) way of defining an abstract class. With C++/CLI, you can use it, or the new abstract keyword. I prefer using the original, since it's just habit, and the abstract keyword is context sensitive in the case of a method, but either works. See: http://msdn.microsoft.com/en-us/library/b0z6b513(VS.80).aspx – Reed Copsey Dec 05 '09 at 01:48