- 2
How does C++ allow the use of static methods in a non static class when C#.net does not allow this ?
Cpp vs C#
6 Respostas
+ 2
Sanjay Kamath oh you meant "instance methods in static classes are not allowed". You were saying the opposite. Well, yeah... apparently you cannot declare non-static members inside static classes in C#.
As to 'why' you can do it in C++, I think it's because in C++, static classes isn't really a thing. Classes declared inside other classes are more like a type declared in the namespace of that class ('static' keyword cannot be used). In other words, the outer class only serves as a path to that type, and the inner class is not really a member of the outer class, only a type declared in it's namespace.
I'm not really sure if that's the reason, or if what I just said makes sense. But that's what I think.
+ 3
What do you mean? Both C++ and C# allow static methods in classes....
Also, the code you've written in your question description looks unrelated to your question. Please remove it.
+ 3
confusing questions get confusing answers. as XXX pointed out, both language have static methods. maybe you meant something else?
+ 1
AFAIK C# does not support static methods in non static classes, C++ does.
+ 1
XXX The reverse is possible in C# but is it possible in C++.
https://code.sololearn.com/c9DBQ7r45L3A/?ref=app