G ++ 3.4.3

xiaoxiao2021-03-06  39

Recently, the company's things are more, there is no time to write to blog write something.

Recently, the company needs to be compiled under G 3.4.3, and the source code is not a Warning in G 3.2.3, but it is a bunch of Error at 3.4.3. Later, I found that the original G 3.4.3 strictly. Among them, the "problem" is the most case:

Class Tobjbase {public: Tobjbase (void): m_nval (0) {} ~ TobJBase (void) {} ​​int getVal (void) const {return m_nval;} void setval (int N) {m_nval = n;} protected: int m_nval ;}; template class textobj: public typeobj {public: textobj (void): typeobj () {} int getExtVal (void) const {return GetVal () 100;}}

This is a relatively common application, and Adapter and Decorator models use this technology. But the problem is that G 3.4.3 said int getextVal (void) const {return getVal () 100;} This line is wrong, getVal () cannot find.

Indeed, you can not find the definition of getVal () with the textobj. G 3.2.3 and VC6, VC7, etc., all believe that this function must be defined elsewhere in other parts of the developer, it is possible to be a member function of TypeObj in other places. But G 3.4.3 does not tell the compiler very responsible for the programmer, which is getVal (), so the solution: method 1: int getExtVal (void) const {return typeObj :: getVal () 100; }

or

Method 2: INT getExtVal (void) const {return this-> getVal () 100;

Of course, if it is an external independent function, that is:

INT getextVal (void) const {return :: getVal () 100;

However, when getVal () is a virtual function, the second method is different from the method, which is a matter of care. Method One is whether TypeObj's getVal () is called, and the method is the most suitable virtual function GetVal ().

转载请注明原文地址:https://www.9cbs.com/read-51317.html

New Post(0)