在 2024-12-06 03:44, i...@wallby.nl 写道:
The following seems to only not work in GCC (neither MinGW nor native GCC), but it compiles fine in MSVC.``` template<typename T> struct A { int numElements; T* elements; }; template<typename T> class B : public A<T> { B(int newNumElements) {numElements = newNumElements; // This fails with error.. 'numElements' was not declared in this scope;elements = new T[numElements]; // This too but with 'elements' instead of 'numElements'
These names can only be found after the template is instantiated [1] so they shall be qualified like `this->numElements`. MSVC behavior is non-standard.
[1] https://en.cppreference.com/w/cpp/language/dependent_name -- Best regards, LIU Hao
OpenPGP_signature.asc
Description: OpenPGP digital signature
_______________________________________________ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public