Should a defect in the C ++ design be submitted to the C ++ Standards Committee? -- You do not need to force a class common member function to declare it in the class body.
Ordinary member functions of the class must be declared in the class to write member functions outside the class. Why must C ++ be designed like this?
1. If you want to add a function, write the same function header twice, which violates the unique information principle. This causes problems such as difficulty in maintenance and synchronization.
2. It is impossible to add a member function to the class outside the library.
For example, I want to add a custom tostring () function to the cstring class of the MFC library.
I think we should design this way. Common class member functions can be defined externally without being declared in the class.
For example, cstring:
Directly in myProgramWrite in
Mylib. cpp:
Lptstr cstring: tostring ()
{
Return (lptstr) (lpctstr) * this;
}
In this way, you can add a tostring member function for the cstring class in the MFC library.
--------------------------
Usemylib. cpp
...
{
.....
Lptstr cstring: tostring (); // you only need to declare it before using it. Of course, you can declare it in a header file.
STR = CSTR. tostring ();
...
}
This problem has been boring for nearly 10 years.
Of course, something like a virtual function must still be declared in the class body.
However, I think BS should have considered this issue for a long time. Why did he use the current solution?