I have some legacy code that I want to upgrade to c++20. The code compiles in c++17 without any issues but fails if I switch to C++20. I simplified the code as much as possible, please look at the example. I am using Visual Studio 2022 on Windows
class MyFile { public: void Read(){ } }; class ArrayWrapper; class BaseClass { public: ArrayWrapper* arrayWrapper; }; template <class T> class ArrayClass : public BaseClass { public: void Add() { arrayWrapper->file.Read(); } }; class ArrayWrapper { public: ArrayWrapper(): file(new MyFile()){ } ~ArrayWrapper() { delete file; } MyFile* file; ArrayClass<int> Array{}; void Update() { Array.Add(); } }; int main() { ArrayWrapper wrapper; wrapper.Update(); } And this is the error message that I am getting:
error C2027: use of undefined type 'ArrayWrapper' message : see declaration of 'ArrayWrapper' message : see reference to class template instantiation 'ArrayClass<T>' being compiled I did look on the stack overflow and in the C++ docs but couldn't figure out what is wrong with this code in C++ 20 Can someone explain how to fix this issue, please?
/std:c++17either. It gives the same expected and self-explanatory error since you have member access into the incomplete typeArrayWrapper. What in the error message is unclear?arrayWrapper->file.Read()is encountered, the compiler doesn't know anything aboutArrayWrapperfile.Readwhich should befile->Readdemo./permissive-when compiling in C++17 mode and it fails there too./permissive-, and setting C++20 or C++latest implies/permissive-while setting C++17 does not.