05-13 04:56
Notice
Recent Posts
Recent Comments
관리 메뉴

Scientific Computing & Data Science

[C/C++] Example / Assignment Operator 본문

Programming/C&C++

[C/C++] Example / Assignment Operator

cinema4dr12 2014. 6. 12. 11:46

const className& className::operator=(const className& rightObject) {
    //local declaration, if any
   
    if (this != &rightObject) { //avoids self-assignment
        //algorithm to copy rightObject into this object
    }
   
    //returns the object assigned
    return *this;
}


EXAMPLE:

Vector& Vector::operator = (const Vector& f) // '=' 연산자 오버로딩
{
    delete[] Vec;

    Len = f.Len;
    Vec = new double[Len];

    for(int i = 0 ; i < Len ; i++)
        Vec[i] = f.Vec[i];

    return (*this);
}

'Programming > C&C++' 카테고리의 다른 글

[C/C++] MFC / 비트맵 출력하기  (0) 2014.06.14
[C/C++] Example / Copy Constructor  (0) 2014.06.12
[C/C++] Example / Double Pointer  (0) 2014.06.12
[C/C++] Example / clockType  (0) 2014.06.12
[C/C++] Example / String Append  (0) 2014.06.12
Comments