X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b4fe51258d17c1e63c55b2b83c8db83e44b15927..e4a71fc3f98e321855aa511e5d84ac08d0b7210a:/docs/html/standard.htm diff --git a/docs/html/standard.htm b/docs/html/standard.htm index fa5270c36e..6cc90a9062 100644 --- a/docs/html/standard.htm +++ b/docs/html/standard.htm @@ -59,8 +59,8 @@ C++ portability guide by David Williams.
+ +You should avoid having overloaded virtual methods in a base class because if +any of them is overriden in a derived class, then all others must be overriden +as well or it would be impossible to call them on an object of derived class. + +For example, the following code: + +
+ class Base + { + public: + virtual void Read(wxFile& file); + virtual void Read(const wxString& filename); + }; + + class Derived : public Base + { + public: + virtual void Read(wxFile& file) { ... } + }; + + ... + + Derived d; + d.Read("some_filename"); // compile error here! ++ +will fail to compile because the base class function taking filename +is hidden by the virtual function overriden in the derived class (this is +known as [virtual] function name hiding problem in C++). + +
+The standard solution to this problem in wxWindows (where we have such +situations quite often) is to make both Read() functions not virtual +and introduce a single virtual function DoRead(). Usually, it makes +sense because the function taking a filename is (again, usually) implemented +in terms of the function reading from a file anyhow (but making only this +functions not virtual won't solve the above problem!). +
+So, the above declarations should be written as: +
+ class Base + { + public: + void Read(wxFile& file); + void Read(const wxString& filename); + + protected: + virtual void DoRead(wxFile& file); + }; + + class Derived : public Base + { + protected: + virtual void DoRead(wxFile& file) { ... } + }; ++ +This technique is widely used in many of wxWindows classes - for example, +wxWindow has more than a dozen of DoXXX() functions which +allows to have many overloaded versions of commonly used methods such as +SetSize() +
Some compilers don't pay any attention to extra semicolons on top level, as in
@@ -515,6 +577,13 @@ While DOS/Windows compilers don't seem to mind, their Unix counterparts don't like files without terminating new-line. Such files also give a warning message when loaded to vim (the Unix programmer's editor of choice :-)), so please think about terminating the last line. + +
+The linker on VMS is case-insensitive. Therefore all external variables and
+functions which differ only in case are not recognized by the linker as
+different, so all externals should differ in more than the case only:
+i.e. GetId is the same as