Új hozzászólás Aktív témák

  • Zulfaim

    csendes tag

    nem tudom hova feltölteni.

    #include <cstring>
    #include <iostream>
    using namespace std;

    class buffer {
    char* buff;
    int size;
    public:
    buffer(){buff=''ZZZ''; size=3;}
    buffer(const buffer&);
    buffer& operator=(const buffer&);
    friend ostream& operator<<(ostream& s, const buffer b);
    ~buffer(){ delete[] buff; }

    buffer& buffer:: operator+=( const char* value)
    {
    char* temp=new char[strlen(buff)+1];
    strcpy(temp,buff);
    if(size+=strlen(value))
    {
    delete[] buff;
    buff=new char[size+1];
    strcpy(buff,temp);
    strcpy(buff+strlen(value),value);
    }
    delete[] temp;
    return *this;

    }


    buffer& buffer:: operator=(const char* value)
    {
    delete[] buff;
    if( size=strlen(value))
    {
    buff=new char[size+1];
    strcpy(buff,value);
    }
    cout<<''__az '=' this-je__''<<*this;
    return *this;
    }

    };
    buffer::buffer(const buffer& e)
    {
    buff=new char[size=e.size];
    for(int i;i<size;i++)
    {
    buff=e.buff;
    }
    }

    buffer& buffer:: operator=(const buffer& e)
    {
    if( this!= &e)
    {
    delete[] buff;
    buff=new char[size=e.size];
    for(int i=0;i<size;i++)
    {
    buff=e.buff;
    }
    }
    return *this;
    }

    ostream& operator<<(ostream& s, const buffer b)
    {
    for(int i=0;i<b.size;i++)
    {
    s<<b.buff;
    }
    return (s);

    }

    int main()
    {
    char s[7]=''BUFFER'';
    buffer b;
    cout<<b;
    b=s;
    cout<<b;
    cout<<endl;
    b+=s;
    cout<<b;
    cin.get();
    return 0;
    }


    most az a baj vele, hogy a this-be ilyen baromságokat rak( memóriaszemét), de nem tudom, hogy mitől kapja. Nem hiszem, hogy a konstruktor hibája lenne.

Új hozzászólás Aktív témák