javaWch 2022-10-07 01:10 采纳率: 0%
浏览 62

使用list的push_back报错

为什么会报错呢?

#include <list>
#include <tchar.h>

namespace Component_WCH
{
    char Button[] = "Button";

    class Component
    {
        private:
            std::list<char[]>Component_attribute;
        public:
            void initVariable()
            {
                Component_attribute.push_back("Button");//type
                Component_attribute.push_back("0");//X
                Component_attribute.push_back("0");//Y
                Component_attribute.push_back("80");//Width
                Component_attribute.push_back("35");//Height
                Component_attribute.push_back("button");//Text
            }

            std::list<char[]> getComponent()
            {
                return Component_attribute;
            }
    };
}
D:\development\C++ development\library\window_WCH\Component.h:15:55: error: no matching function for call to 'std::__cxx11::list<char []>::push_back(const char [7])'
   15 |                 Component_attribute.push_back("Button");//type
      |                                                       ^
In file included from d:\c\lib\gcc\mingw32\9.2.0\include\c++\list:63,
                 from D:\development\C++ development\library\window_WCH\Component.h:1,
                 from D:\development\C++ development\library\window_WCH\window.h:4,
                 from View++/main.cpp:2:

为什么呢?

  • 写回答

1条回答 默认 最新

  • 浪客 2022-10-07 09:27
    关注

    std::list<char[]>改为std::list<const char*> ,char[]数组大小不明确。

    评论

报告相同问题?

问题事件

  • 创建了问题 10月7日