如何解决为什么`string` `vector` 等在野牛的联合中不起作用?
我试图为 C 语言的一个子集编写解析器。但是当我在 string
中包含 vector
或 %union
时,它会抛出 error 。使用 char*
或 array
似乎没问题。
%union{
string s;
vector<int>v;
}
%code requires{
#include <string>
}
对于字符串大小写。但这对我也不起作用。
我得到的错误是
y.tab.c:1174:9: error: use of deleted function ‘YYSTYPE::YYSTYPE()’
YYSTYPE yylval;
^~~~~~
y.tab.c:223:7: note: ‘YYSTYPE::YYSTYPE()’ is implicitly deleted because the default deFinition would be ill-formed:
union YYSTYPE
^~~~~~~
demo.y:48:12: error: union member ‘YYSTYPE::s’ with non-trivial ‘std::__cxx11::basic_string<_CharT,_Traits,_Alloc>::basic_string() [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’
string s;
^
demo.y:49:16: error: union member ‘YYSTYPE::v’ with non-trivial ‘std::vector<_Tp,_Alloc>::vector() [with _Tp = int; _Alloc = std::allocator<int>]’
vector<int>v;
^
y.tab.c: In function ‘int yyparse()’:
y.tab.c:1203:30: error: use of deleted function ‘YYSTYPE::YYSTYPE()’
YYSTYPE yyvsa[YYINITDEPTH];
^
y.tab.c:1203:30: error: use of deleted function ‘YYSTYPE::~YYSTYPE()’
y.tab.c:223:7: note: ‘YYSTYPE::~YYSTYPE()’ is implicitly deleted because the default deFinition would be ill-formed:
union YYSTYPE
^~~~~~~
demo.y:48:12: error: union member ‘YYSTYPE::s’ with non-trivial ‘std::__cxx11::basic_string<_CharT,_Alloc>::~basic_string() [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’
string s;
^
demo.y:49:16: error: union member ‘YYSTYPE::v’ with non-trivial ‘std::vector<_Tp,_Alloc>::~vector() [with _Tp = int; _Alloc = std::allocator<int>]’
vector<int>v;
^
y.tab.c:1203:30: error: use of deleted function ‘YYSTYPE::~YYSTYPE()’
YYSTYPE yyvsa[YYINITDEPTH];
^
y.tab.c:1215:11: error: use of deleted function ‘YYSTYPE::YYSTYPE()’
YYSTYPE yyval;
^~~~~
y.tab.c:1215:11: error: use of deleted function ‘YYSTYPE::~YYSTYPE()’
y.tab.c:1381:14: error: use of deleted function ‘YYSTYPE& YYSTYPE::operator=(const YYSTYPE&)’
*++yyvsp = yylval;
^~~~~~
y.tab.c:223:7: note: ‘YYSTYPE& YYSTYPE::operator=(const YYSTYPE&)’ is implicitly deleted because the default deFinition would be ill-formed:
union YYSTYPE
^~~~~~~
demo.y:48:12: error: union member ‘YYSTYPE::s’ with non-trivial ‘std::__cxx11::basic_string<_CharT,_Alloc>& std::__cxx11::basic_string<_CharT,_Alloc>::operator=(const std::__cxx11::basic_string<_CharT,_Alloc>&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’
string s;
^
demo.y:49:16: error: union member ‘YYSTYPE::v’ with non-trivial ‘std::vector<_Tp,_Alloc>& std::vector<_Tp,_Alloc>::operator=(const std::vector<_Tp,_Alloc>&) [with _Tp = int; _Alloc = std::allocator<int>]’
vector<int>v;
^
y.tab.c:1412:24: error: use of deleted function ‘YYSTYPE& YYSTYPE::operator=(const YYSTYPE&)’
yyval = yyvsp[1-yylen];
^
y.tab.c:1569:14: error: use of deleted function ‘YYSTYPE& YYSTYPE::operator=(const YYSTYPE&)’
*++yyvsp = yyval;
^~~~~
y.tab.c:1713:14: error: use of deleted function ‘YYSTYPE& YYSTYPE::operator=(const YYSTYPE&)’
*++yyvsp = yylval;
^~~~~~
y.tab.c: In function ‘void __static_initialization_and_destruction_0(int,int)’:
y.tab.c:1174:9: error: use of deleted function ‘YYSTYPE::~YYSTYPE()’
YYSTYPE yylval;
^~~~~~
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。