<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Forum Pasja Informatyki - Najnowsze z tagiem compilation_failed</title>
<link>https://forum.pasja-informatyki.pl/tag/compilation_failed</link>
<description>Powered by Question2Answer</description>
<item>
<title>[C++]  error: use of deleted function class::&lt;unnamed union&gt;::&lt;constructor&gt;()</title>
<link>https://forum.pasja-informatyki.pl/359775/c-error-use-of-deleted-function-class-unnamed-union-constructor</link>
<description>

&lt;p&gt;Witam.&lt;/p&gt;



&lt;p&gt;Mam pewien problem którego rozwiązania nigdzie nie mogę znaleźć.&lt;/p&gt;



&lt;p&gt;Tak wygląda moja klasa:&lt;/p&gt;



&lt;pre class=&quot;brush:cpp;&quot;&gt;
class Matcher{
    public:
        Matcher(std::string expr);
        ~Matcher();
        template&amp;lt;typename T&amp;gt; T GetConstant();
        const char* GetConstantValue();
    private:
        union{
            std::string str;
            char sing;
        }constant;
        UsedValue UsedVal; //wcześniej jest enum
        std::string ConstantValue;
        std::stack&amp;lt;std::map&amp;lt;std::string, std::string&amp;gt;&amp;gt; MatcherJuxtaposition;
};&lt;/pre&gt;



&lt;p&gt;kompilator wykrywa błąd w&amp;nbsp;pliku Matcher.cpp:&lt;/p&gt;



&lt;pre class=&quot;brush:cpp;&quot;&gt;
#include &quot;Matcher.h&quot;


Matcher::Matcher(std::string expr){
    const char* regex=&quot;([A-Z]*|([A-Z]|[0-9])*)=(\&quot;.+\&quot;|rand\((\s*[0-9]+\s*|(\s*[0-9]+\s*,\s*[0-9]+\s*))\))&quot;;
    if(!std::regex_match(expr, std::regex(regex){
        std::cout&amp;lt;&amp;lt;&quot;\&quot;&quot;&amp;lt;&amp;lt;expr&amp;lt;&amp;lt;&quot;\&quot; is incorrect.&quot;;
        delete regex;
        exit(1);
    }
    char CurrentChar;
    std::string constant;
    int iterator=0;
    do{
        CurrentChar=expression[iterator];
        expr.erase(0,1);
        constant+=CurrentChar;
    }while(CurrentChar!='=');
    if(constant.length()&amp;gt;1){
        this-&amp;gt;constant.str=constant;
        this-&amp;gt;UsedVal = STR;
    }
    else{
        this-&amp;gt;constant.sing=constant.c_str();
        this-&amp;gt;UsedVal = CHAR;
    }

    delete regex;
}

template&amp;lt;typename T&amp;gt; T Matcher::GetConstant(){
    if(this-&amp;gt;UsedVal==STR) return this-&amp;gt;constant.str;
    return this-&amp;gt;constant.sing;
}

std::string Matcher::GetConstantValue(){return this-&amp;gt;ConstantValue;}
&lt;/pre&gt;



&lt;blockquote&gt;


&lt;p&gt;matcher.cpp: In constructor 'Matcher::Matcher(std::__cxx11::string)':
&lt;br&gt;
matcher.cpp:4:34: error: use of deleted function 'Matcher::&amp;lt;unnamed union&amp;gt;::&amp;lt;con
&lt;br&gt;
structor&amp;gt;()'
&lt;br&gt;
&amp;nbsp;Matcher::Matcher(std::string expr){
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ^
&lt;br&gt;
compilation terminated due to -Wfatal-errors.&lt;/p&gt;
&lt;/blockquote&gt;



&lt;p&gt;Nigdzie nie mogę znaleźć rozwiązania mojego problemu. Konstruktor jest normalny, więc nie rozumiem o co chodzi.&amp;nbsp;&lt;/p&gt;



&lt;p&gt;&amp;nbsp;&lt;/p&gt;



&lt;p&gt;Jeśli ktoś mógłby pomóc, byłbym bardzo wdzięczny.&lt;/p&gt;



&lt;p&gt;&amp;nbsp;&lt;/p&gt;



&lt;p&gt;Pozdrawiam, Hiskiel.&amp;nbsp;&lt;/p&gt;</description>
<category>C i C++</category>
<guid isPermaLink="true">https://forum.pasja-informatyki.pl/359775/c-error-use-of-deleted-function-class-unnamed-union-constructor</guid>
<pubDate>Thu, 21 Jun 2018 13:47:03 +0000</pubDate>
</item>
</channel>
</rss>