Q:

About the new modifier in C#

I don't quite understand the modifiernew in C#: In which way is the following code different depending on the presence of the new modifier?
class A 
    {
        public void F() { Console.WriteLine("A::F()"); }
    }

class B : A
    {
    public new void F() { Console.WriteLine("B::F()"); }

    public static void Main()
    {
        A a = new B();
        B b = new B();
        A trueA = new A();
        a.F();
        b.F();
        trueA.F();
        Console.ReadLine();
    }
}

Is there any equivalent or similar thing in C++?

A:

The result is the same if you are using public void F() or public new void F() in the class B. The method will still be shadowed.
The difference is that if you omit the new modifier, you will get a compiler warning because the code may be confusing. The new modifier is used to specify that you actually intended to shadow a member from the base class, and didn't just happen to use the same name by mistake.

