0

What can be counted as a visible difference between C# and C++ OOP standard definitions? I'm especially interested in anything related to visibility of overloaded/overrided methods.

It seems that C# implements a subset of C++ inheritance order based of stack call order in a class chain; Is that true? Or C# OOP is something different from C++? (Of course, C# has native reflection support, but I'm more interested in finding issues related to inheritance or, probably, compositing).

Is there a well-known situation, in which class N: .. class B: A { } in C++ can't access the base class data (under any possible conditions) that is possible in C#?


I am strongly against recognizing this question as "already answered". Nothing on 'internal' was said, abstract classes can't be clearly evaluated to C++ protected constructor / virtual constructor classes (and the whole interface thing is different with C++). Thus, please don't close the bounty if I have the chance to open it - there surely must be more differences.

Community
  • 1
  • 1
kagali-san
  • 2,964
  • 7
  • 48
  • 87
  • What do you mean by “C# implements a subset of C++ inheritance order based of stack call order in a class chain”? That sentence doesn’t make sense to me. – Konrad Rudolph Oct 21 '13 at 15:32
  • possible duplicate of [C# vs C++ - Types, inheritance and vtable](http://stackoverflow.com/questions/9727827/c-sharp-vs-c-types-inheritance-and-vtable) – Bassam Alugili Oct 21 '13 at 15:35
  • @BassamAlugili That question is about one particular difference between inheritance of C# and C++. This question is asking for *all* of the differences, making it "too broad" instead. – Servy Oct 21 '13 at 15:47
  • Define "any possible conditions". Knowing memory layout of the base class you can access memory it resides directly to read or change object's private members. – n0rd Oct 21 '13 at 16:02

2 Answers2

2

c++ supports Multiple inheritance, whereas C# doesn't that is probably the biggest differences.

user2711965
  • 1,795
  • 2
  • 14
  • 34
2

I'm sure you can find a whole book on this stuff. One big change is when defining a class in C#, you can only inherit from one base class. C++ you can inherit from multiple.

Is there a well-known situation, in which class N: .. class B: A { } in C++ can't access the base class data (under any possible conditions) that is possible in C#?

If the base class is protected or public.

The protected keyword is a member access modifier. A protected member is accessible within its class and by derived class instances. (Source: http://msdn.microsoft.com/en-us/library/bcd5672a.aspx)

gleng
  • 6,185
  • 4
  • 21
  • 35
  • following works in C++: namespace XX { class Nest { protected: class Zero { protected: int xx; }; class St : Zero { public: void Test() { xx = 1; } }; }; } – kagali-san Oct 21 '13 at 16:34
  • 1
    I was referring to them in the sense that, the base class has protected members which are accessible through the derived class type. I've updated my answer @kagali-san – gleng Oct 21 '13 at 16:58