Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the 'ref' and 'sealed' keywords in C++?

Tags:

c++

ref

sealed

I've just seen some (presumably) C++ code which sports two "keywords" unknown to me (I'm assuming keywords but, since I have no context, they may be simple #define things).

They also don't seem to appear in the C++11 standard, at least the draft I have but, since that's a pretty late draft, I can't imagine them being just dropped into the standard at the last minute. They are ref and sealed.

The code I found them in was something like:

public ref class DevIface sealed {
    private:
        int currOffset;
public:
        DevIface (int initOffset);
        : : :

Does anyone know what these keywords are, and what they're meant to achieve?

like image 345
paxdiablo Avatar asked Sep 26 '11 02:09

paxdiablo


People also ask

What is sealed keyword in C#?

Sealed classes are used to restrict the users from inheriting the class. A class can be sealed by using the sealed keyword. The keyword tells the compiler that the class is sealed, and therefore, cannot be extended. No class can be derived from a sealed class.

What are sealed classes?

Sealed classes and interfaces represent restricted class hierarchies that provide more control over inheritance. All direct subclasses of a sealed class are known at compile time. No other subclasses may appear outside a module within which the sealed class is defined.

Why do we need sealed class in C#?

We use sealed classes to prevent inheritance. As we cannot inherit from a sealed class, the methods in the sealed class cannot be manipulated from other classes. It helps to prevent security issues.

What is sealed modifier?

The sealed modifier is used to prevent derivation from a class. An error occurs if a sealed class is specified as the base class of another class.


1 Answers

This is C++/CLI.

A ref class is a managed type.
sealed means that the class cannot be inherited

like image 161
SLaks Avatar answered Oct 11 '22 10:10

SLaks