N
Nephi Immortal
I am trying to compare assignment operator to the main class’ pointer
while it is performing the task inside helper class’ operator=
function.
Please let me know if my code is to be correct design since I put
helper class inside main class.
typedef unsigned int size;
class A {
private:
struct B {
B() {}
~B() {}
B &operator=( const B &r ) {
if( a == r.a )
return *this;
a->m_data = r.a->m_data;
return *this;
}
B &operator=( const size ) {
return *this;
}
operator size() { return 0; }
operator size() const { return 0; }
A *a;
};
public:
A( size data ) : m_data( data ) {
b.a = this;
}
~A() {}
B &Go() {
return b;
}
private:
size m_data;
B b;
};
int main () {
A a( 0x25 ), a2( 0x7C );
a.Go() = a.Go(); // Skip assignment operator to the same object
a.Go() = a2.Go();
return 0;
}
while it is performing the task inside helper class’ operator=
function.
Please let me know if my code is to be correct design since I put
helper class inside main class.
typedef unsigned int size;
class A {
private:
struct B {
B() {}
~B() {}
B &operator=( const B &r ) {
if( a == r.a )
return *this;
a->m_data = r.a->m_data;
return *this;
}
B &operator=( const size ) {
return *this;
}
operator size() { return 0; }
operator size() const { return 0; }
A *a;
};
public:
A( size data ) : m_data( data ) {
b.a = this;
}
~A() {}
B &Go() {
return b;
}
private:
size m_data;
B b;
};
int main () {
A a( 0x25 ), a2( 0x7C );
a.Go() = a.Go(); // Skip assignment operator to the same object
a.Go() = a2.Go();
return 0;
}