C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Allow forward declarations of typedef'ed classes

From: Sebastian Wittmeier <wittmeier_at_[hidden]>
Date: Tue, 20 Feb 2024 23:55:36 +0100
Hi Frederick,   what is the problem? The following code compiles just fine:       template<bool temp_param_record>     class Donkey;     typedef Donkey<true> Monkey;     int Func(Monkey *const p)     {         returnnullptr == p;     }     template<bool temp_param_record>     class Donkey {         int number;     };     int main(void)     {         Monkey obj;     }       -----Ursprüngliche Nachricht----- Von:Frederick Virchanza Gotham via Std-Proposals <std-proposals_at_[hidden]> Gesendet:Di 20.02.2024 10:49 Betreff:[std-proposals] Allow forward declarations of typedef‘ed classes An:std-proposals <std-proposals_at_[hidden]>; CC:Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>; I had a header file "record.h" something like as follows:    class IDevice;    int Record( IDevice * ); I put in a forward declaration for 'IDevice, because I didn't want to include the header file that defines 'IDevice' for two reasons:    (1) To reduce compile time    (2) To avoid a circular dependency This worked fine until the person who maintained 'IDevice' did the following inside "IDevice.hpp":    template<bool temp_param_record>    class Interface {    public:        static consteval bool record(void) noexcept { return temp_param_record; }    };    typedef Interface<true> IDevice; So now any source file that does the following:    #include "IDevice.h"    #include "record.h" fails to compile. So I propose that the following be valid C++:    class Monkey;    int Func(Monkey *const p)    {        return nullptr == p;    }    class Donkey {        int number;    };    typedef Donkey Monkey;    int main(void)    {        Monkey obj;    } I propose that we should be able to do a forward declaration of a typedef'ed class. -- Std-Proposals mailing list Std-Proposals_at_[hidden] https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2024-02-20 22:55:38