C++ programming style

前端 未结 16 1695
眼角桃花
眼角桃花 2021-02-07 22:33

I\'m an old (but not too old) Java programmer, that decided to learn C++. But I have seen that much of C++ programming style, is... well, just damn ugly!

All that stuff

16条回答
  •  你的背包
    2021-02-07 22:53

    If you want to implement all your methods inside your class definitions, you will have big monster header files (it's not a good idea to declare classes in cpp files) and possibly only one cpp file (the one that has your main function).

    So it's a matter of convenience.


    Edit:

    I find the declaration-implementation separation actually helpful. When I have monster classes with ~150 methods whose implementation is generated using lots of preprocessor tricks, I often want to be able to tell the difference between...

    • what the class can do (its interface, given by its declaration)
    • how the class does it (its implementation)

    Not being able to do that in either C# or Java is quite frustrating, especially when I don't have Intellisense at hand.

提交回复
热议问题