views:

171

answers:

2

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

public abstract class SomeClass
{
    public abstract String SomeMethod();
}
+3  A: 

You use abstract:

public ref class SomeClass abstract
{
    public:
        virtual System::String^ SomeMethod() = 0;
}
Reed Copsey
Is there any difference between declaring "SomeMethod() = 0" and "SomeMethod() abstract"?
Lopper
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
@Reed Copsey: Thanks!
Lopper
+1  A: 

Just mix up the keywords a bit:

public ref class SomeClass abstract {
public:
  virtual String^ SomeMethod() abstract;
};
Hans Passant
Is there any difference between declaring "SomeMethod() = 0" and "SomeMethod() abstract"?
Lopper
No. = 0 is C++ syntax but C++/CLI supports it too.
Hans Passant
@nobugz: Thanks!
Lopper