Why can't I initialize an array of objects if they have private copy constructors?

前端 未结 4 385
夕颜
夕颜 2021-01-24 08:34

I just ran across some unexpected and frustrating behaviour while working on a C++ project. My actual code is a tad more complicated, but the following example captures it just

4条回答
  •  余生分开走
    2021-01-24 09:01

    class Irritating
    {
        public:  Irritating() {}
        private: Irritating(const Irritating& other) {}
    };
    
    enum DefaultConstruct { defaultConstruct };
    
    class MaybeTooClever
        : public Irritating
    {
    public:
        MaybeTooClever( DefaultConstruct = defaultConstruct ) {}
    #ifdef __GNUC__
    public:
        MaybeTooClever( MaybeTooClever const& other );      // No such.
    #else
    private:
        MaybeTooClever( MaybeTooClever const& other );      // No such.
    #endif
    };    
    
    static MaybeTooClever const array[] = { defaultConstruct };
    
    int main()
    {}
    

提交回复
热议问题