C++ 重载运算符分段的返回值失败

C++ 重载运算符分段的返回值失败,c++,class,return,C++,Class,Return,头球进洞 DuzaLiczba operator>(const DuzaLiczba& right) const; string& getData(); virtual ~DuzaLiczba(); private: string& data; 在我的类中,重载运算符返回“\002\994\23923”中的字符串 大体上 cout << dl3.getData(); cout.flush(); cout 我只想返回一个

头球进洞

DuzaLiczba operator>(const DuzaLiczba& right) const;
string& getData();
virtual ~DuzaLiczba();
private:
string& data;
在我的类中,重载运算符返回“\002\994\23923”中的字符串

大体上

        cout << dl3.getData();
        cout.flush();
cout
我只想返回一个字符串。
dl1=“123089127312890372109371203971293012903”
dl2=“12837129037812903812903”
例如DuzaLiczba dl3(dl1+dl2)
而且不能

课内代码做数学很棒


或者创建重载运算符“您不应该在类中保留引用。您保留了对局部变量的引用,该局部变量被破坏,然后被访问,导致分段错误。此外,运算符>和运算符什么运算符返回sting?您可以发布getData()的代码吗?字符串“\002\994\23923”\“不是C++中的有效字符串。我们也缺少构造函数。我猜您引用的对象无效。确保所引用的对象(字符串?)仍处于活动状态,或使用引用计数指针。似乎与此类似:而且可能是
cout.flush()函数的最后一行?如果是这样的话,我猜应该归咎于
~DuzaLiczba
。你应该编辑你的问题并添加此代码。这不是您问题的答案。如果要添加或修改您的问题,请使用“编辑”按钮。答案是留给,嗯,答案。
        cout << dl3.getData();
        cout.flush();
class DuzaLiczba {
public:
    DuzaLiczba(string& input);
    DuzaLiczba(const DuzaLiczba& orig);
    bool operator==(const DuzaLiczba &other) const;
    bool operator!=(const DuzaLiczba &other) const;
    DuzaLiczba operator+(const DuzaLiczba& right) const;
    DuzaLiczba operator-(const DuzaLiczba& right) const;
     DuzaLiczba operator<(const DuzaLiczba& right) const;
    DuzaLiczba operator>(const DuzaLiczba& right) const;
    string& getData();
    virtual ~DuzaLiczba();
private:
    string& data;

};
bool DuzaLiczba::operator==(const DuzaLiczba &other) const {
string liczba1 = this->data;
string liczba2 = right.data;
char index1 = liczba1.length();
char index2 = liczba2.length();
short k;
short o;
short f = 0; //przeniesienie
string wynik;
int sizefi = 0;
char temp;
int i = 0;
//"gupie" to C# RUUUULEEEZ
// http://www.youtube.com/watch?v=bXoc9hOIj3M hahahaa "D

if (liczba1.length() == liczba2.length()) { //najpierw dlugosc szybciej niz pokolei
    for (i = 0; i < index1; i++) { 
        if (liczba1[i] == liczba2[i]) {   //sprawdza kazdy element jesli sie rozni to false
            wynik =
                    "TRUE";

        } else {
            wynik = "FALSE";
        }

    }

} else {
    wynik = "FALSE";
}

return DuzaLiczba(wynik);

 }
string& DuzaLiczba::getData() {
 return data; //zwoloniony string
     }